Topic category: Troubleshooting, bugs, and solutions
Hello. Found an error fetching information about the state of the player's hunger level.
I was working on a new meal. I wanted the food not to restore the hunger level immediately, but to do it gradually. To make this happen, I assigned an effect to the player after eating food.
The effect is set to regenerate hunger, once per second. This event worked once every 20 ticks.
When testing began, I noticed a strange bug.
Let's say the hero has 5 food points.
Every second food is added to the player.
At one of the moments, while the player is running, the game takes away one point of food from him (5-1 = 4). After a moment, a script is triggered to increase hunger points. And instead of adding points to the number 4, which we got after a run, the program takes outdated data (5 + 1 = 6).
Perhaps it is difficult for you to understand my text, for this I have attached a video. Notice how hunger works. Running takes away a food point, and restoring it ignores this fact.
It seems to me that this is out of sync programm. I did a lot of tests and found that the problem is in the "get food"
The game takes incorrect data and cannot adequately work with them accordingly.
You might think that the problem is in my crooked code, but it is not. Try to play around with the hunger information fence yourself, and change it over time, and not instantly. It seems to me that the information that is taken on hunger is outdated, and works as if outside the tick system.
Instead of ticks, you can simply put a random chance of execution. And sooner or later you will see out of sync. Even trivial, if you stand still and randomize a chance, hunger recovery will be wildly buggy and the values will jump from high to low.
I remind you that the script is executed on the active tick of the effect. In general, I also tested not on effects. It's the same everywhere.
This is a basic element of interaction with the player, and it is unrealistic to bypass any bridge.
I admit the possibility of a mistake on my part, or not understanding how the code functions, if I made a mistake myself, then I hope that you will explain what I did wrong.