I'm having trouble getting it to work in game I think it's because by default the variables
I created values start at zero
Well it sounds like you have the answer already.
Variables need to be initialized. Technically, without any sort of control variable script or command, they are set to a null value which
most of the time the game interprets as 0. (there are some instances where it doesn't)
There are a few ways you can do this.
You can either create a "game start" event, which will initialize any necessary game variables.
Or, you can put a conditional branch at the top of your hunger parallel common event. Have the conditional check something like a switch or variable - whatever it may be - which determines if the game has started. If it has not started yet, set the hunger variables.
It's probably easier to put the variables in an initializing event, so I recommend that one.
Second, I recommend changing your conditional checks "if hunger = 0".
I would change it to equal to or less than 0.
The reason is that, it is only checking if the value is exactly 0. You are subtracting 3 value at a time, so it's possible that 0 could be skipped altogether. For example, if the player has 2 hunger, and it ticks over, then the player has -1 hunger; the value never reached 0 and so the conditions are ignored.
Thirdly, you have nothing preventing the hunger going negative. So basically, you characters can go into hunger debt now.
After the hunger value reaches 0, nothing disables the hunger meter, it will continue to count. So now, every 120 frames, they will lose 3 hunger points; going from 0, to -3, to -6, to -9, -12, etc.
(the reverse can also be said, as nothing is preventing the hunger meter from exceeding 100 either, allowing players to eat 100 apples and have 1000 hunger points)
There are a few ways you can fix this.
1) set a conditional after all the hunger calculations: if hunger is less than 0, set hunger to 0.
2) a more intelligent way to go about this is to turn the processing off for this event, then have your food items turn it back on.
So, if hunger is equal to or less than 0, turn off hunger and thirst (switch). Then when the player eats food or drinks water, have the food run a common event to set values.
For example an apple common event:
Code:
If hunger is less than 0:
Set hunger to 0.
End
Control variable: hunger + 10.
Turn on "hunger and thirst"
Good luck and try not to catch cholera.
👋