Forum Discussion
Avoiding Negative Number Variables - Set variable to a value (0), but it presents as to a variable
Hello! I'm working on building an eLearning game that uses points, and keeps track of the players score based on how long it takes them to answer the question correctly (or how quickly they answer incorrectly). For this I'm using a few variables - Points, to keep track of how many points the learner will earn (or lose) for each question, and PlayerScore, to keep track of how many points the learner has.
I never want the learner to have a negative score. So, I thought I could use conditions and an else statement to make it so if PlayScore is less than or equal to Points, PlayScore would be set to 0. So if a learner had a score of 30 points, but answered incorrectly and were to lose 40 points, they would have a score of 0 points instead of -10 points.
However, when the Trigger Wizard is set to adjust the variable by value, it prompts me as if I've set it to adjust the variable by variable. Clicking the red unassigned only prompts me with variables.
I've seen that bug. As a workaround, instead of value in the else statement use random number between and set the top and bottom numbers to the same value (for example, 0).
- Nathan_HilliardCommunity Member
I've seen that bug. As a workaround, instead of value in the else statement use random number between and set the top and bottom numbers to the same value (for example, 0).
- Nathan_HilliardCommunity Member
Regarding your trigger logic, instead of the condition 'if PlayerScore <= Points' I think you want >=. You only want to subtract if there are enough points in the score, otherwise you set the score to zero.
- kscaramuzziCommunity Member
I blame morning brain! You're very correct. I just realized that, so I edited my post to reflect that. But you're right, the value/variable bug is still there. Thank you!!