How do I get the global variable modification to calculate correctly?

This game starts with trivia, once the player has won their money, they take their money to the next scene as a global variable ‘quizextension_moneywon’. Upon loosing the scene, the global variable ‘quizextension_moneywon’ should be decreased by 500. However, it is not decreasing, it is increasing to no limits. In addition, Minda’s forces aren’t removed. Help?

Hi, just a thought. If the points are not subtracted and the force is not removed there might be a problem with your conditions (hours_number = 24 and SheepFound = 0). I could not find that on your screenshot (it is very small on my screen) but is there any event that assigns the two values (24 and 0) to your variables?

In Sheep Search group you have a comment creating a random number and storing it in a scene variable random, but I can’t see that in your actions. Are you sure your code is ok?

1 Like

Hi, thanks for the reply. Yes, the timers increase these variables, the hours_number and days_number timers advance. Once hours hits ‘24’ it signals another day. So if hours hits 24 and the sheep isn’t found, points should be lost and the level as well.

I updated it a bit, still doesn’t work. See the entire code below:

Whoops, that is an old comment.

The code should go: In ‘SheepGroup’, there are 4 different sheep (sheep1, sheep2, etc). Randomly assign the position of the sheep behind eachsheep coin. Only create 1 instance of Sheep1. Once Minda collides with sheepcoin, reveal which sheep. If Minda collides with Sheep1 (before hour 24), show ‘win’ .

You have the variable SheepFound whose value is 1 when Minda is in collision with SheepCoin. Maybe I miss that part but I don’t really understand under which condition 0 is assigned to SheepFound in your event sheet. But SheepFound = 0 is necessary for triggering the actions that seem not to work in your events.

I modified it, and set it =0, it still doesn’t work.

Well, I thought you might want to set the variable at the beginning of the scene to 0 and if Minda finds Sheep1 it will be set to 1. If it stays 0 + hours_number = 24 the listed actions will be executed. If this doesn’t work, I have no better idea at the moment.

Yea, I did that, but still no luck. The points aren’t adding correctly and neither my timers - ‘hours’ won’t unpause or reset at SheepFound=2. Instead ‘Hours’ unpauses at SheepFound=3 and then once it hits 24, days starts counting without stopping (which is the same thing that the points does). Not sure if the issues are related. Appreciate the help anyway.

couple of things:

When your variable Hours_num is => 24 you add 1 to variable day, each frame.
you need to add +1 to Day and then set Hours back to 0, or you get +1 day, each frame.
then you need to put your score, show loose layer, ect as a subevent of your first hours>=24, since it will reset
or replace your condition hours >=24 with day =1
then this condition needs a trigger once, or the score will be subtracted each frame.

i dont know, why you set days to 14 when sheep found = 2

to your subtract score events:
does the layer “loose” show up?

1 Like

Thanks, that works for the most part. Layer ‘lose’ shows up and the points are calculating correctly. (The timers advances to day 14 after the player views the ‘hint’ which is why ‘Day’ is set to 14.)

The timers now reset and stop correctly but the issue of it the “Hours” unpausing at SheepFound=3 instead of sheepfound=2 is still a problem.

When sheepfound = 2
You reset the timer, each frame.
That essentially stops your timer, since it cannot reach 1 second. The timer continues only if sheepfound is not 2 anymore

1 Like