C-Dawg
06-01-2008, 03:39 PM
I have several global scripts that react to changes in game variables. When link's max health increases, a little message pops up going "HEALTH UP!" When you change screens, enemies frozen by the freeze ray dissapear.
In both cases, I detect the change by having variables called "last_health" or "last_screen." At the end of the script's while loop, I load the current health or current screen into this variable. At the beginning of the loop, I check to see if last_health or last_screen no longer agrees with the current screen. Works great.
But, in the case of health and screen changes, one frame isn't enough. For some reason, I need to compare the current screen to the screen TWO frames ago, not one, to detect the change. Ditto for health.
So at the end of each loop, I load last_screen into last_screen2, then load the current screen into last_screen. So it takes two frames to propagate through the script.
Current screen -> last screen -> last screen2.
Now, this works. But why? And for what other game variables can changes only be detected every two frames instead of each frame?
In both cases, I detect the change by having variables called "last_health" or "last_screen." At the end of the script's while loop, I load the current health or current screen into this variable. At the beginning of the loop, I check to see if last_health or last_screen no longer agrees with the current screen. Works great.
But, in the case of health and screen changes, one frame isn't enough. For some reason, I need to compare the current screen to the screen TWO frames ago, not one, to detect the change. Ditto for health.
So at the end of each loop, I load last_screen into last_screen2, then load the current screen into last_screen. So it takes two frames to propagate through the script.
Current screen -> last screen -> last screen2.
Now, this works. But why? And for what other game variables can changes only be detected every two frames instead of each frame?