Let's try to put this stuff to rest with a little emperical evidence...😎
Attached is a script file containing some global scripts. Import it into a simple quest and compile it.
For the first example, assign the script "Slot_2_No_Loop" to global slot 2. Then play your quest. After a few seconds of playing, pause the game (hit the ESC key, for instance). Now go browse to your Zelda Classic folder, and find the "allegro.log" file. Open it (any text editor will do). Scroll to the bottom. You should see one number written there...if it's the first time you've tried this experiment, it should be 0; whatever it is, there should only be one number there. What does this demonstrate? It demonstrates that the Slot 2 script, without any fancy while loops or anything, only gets called once. If it were automatically called every frame, the log file would be filled to the brim with numbers.
As a second example, edit your quest so that global slot 2 is assigned the "Slot_2_While_Loop" script. Play your quest again. This time, hit the "A" button a few times (keep count of how many times you hit it), then pause the game and look at the allegro.log file again. You should see a block of numbers for each time you hit the "A" button. This demonstrates that you can get the slot 2 script to run continuously with a while loop, and that you can call the Waitframe() function in a global script. You have to call the waitframe function in this case, or your game will freeze because it will get stuck in one of the while loops.
As the third example, set up the global slot 3 script to call the Slot_3 script. Play the quest again. Walk around for awhile, whatever, but then pause the game and look at the allegro.log file. You won't see the "1234" that the script is supposed to write to the log file. Go back to your game, play around a bit, then using the menus QUIT (not exit) the game. You'll get to the Continue/Retry/Save screen. Click retry. Now look at allegro.log. You'll see the 1234. Start the experiment over, and this time just get yourself killed. Again, you'll see the 1234 in the log file. I'm not sure entirely what this implies, other than the Slot 3 script evidently gets called when Link dies or when you quit the game.
Perhaps someone can extend this little experiment and we can learn more....?
// Standard imports.
import "std.zh"// Global variables.
int Slot_2_Count = 0;
global script Slot_2_No_Loop{
void run(){
// Just increment a counter and dump it
// to the log file.
Trace(Slot_2_Count++);
} // end run
}
global script Slot_2_While_Loop{
void run(){
// Dump something to the log file everytime
// you press the "A" button. Monitor forever.
// Note how the game doesn't freeze. Note that
// since the frames pass faster than you can
// press the button, you'll get multiple log
// entries for a single button press.
while(true){
if(Link->InputA){
while(Link->InputA){
Trace(Slot_2_Count);
// Call Waitframe() or we'll freeze the game.
Waitframe();
}
// Update the counter so we get a new value
// next time we press the A button.
Slot_2_Count++;
}
// Call Waitframe() otherwise the game will freeze.
Waitframe();
}
} // end run
}
global script Slot_3{
void run(){
// Dump something to the log file so
// we know when this script actually
// gets called.
Trace(1234);
}
}