Zelda Classic Tutorials
 
 

Global Tick Script

Zelda Classic allows you to specify three global scripts. Unlike the other two types of scripts (FFC and Item), each global script slot does different things. The first slot is the "Init" script, and should always be the magical "~Init" script provided by the compiler.

However, this tutorial focusses on the second slot, which is the "OnStart" script. This script is run at the beginning of a new game session (i.e. after you fire up a save slot), and is killed (if it's still running) when Link dies (needs confirming).

When should you use it?

Generally, you don't need it for using FFC scripts, but it comes in handy with any but the most trivial Item scripts (which, by themselves, cannot run more than one frame for no particular reason). Certain other scripts on this site do require it, and will link to this page when this is the case.

How to create it

For your sake and mine, please use a very specific layout when creating startup script. I will provide you a template:

Show/Hide < code block hidden >
import "std.zh"

//global variables go here

global script onstart {
  void run() {
   
    //one time things go here
   
    while(true) {
     
      //function calls go here
     
      Waitframe();
    }
  }
 
  //functions go here
}

Copy that into your script file, and fill in the blanks. When you add scripts (at least, from this site), they will come in two or three parts: The function body, the function call, and any global variables it uses. The global variables go at the very top:

bool somethingfoo = false;

The function call, which runs this, goes in the middle, either in the "one time" section or in the loop. Most of the time, the call will go in the loop, but read the instructions on the particular script to find out where. Regardless, it will look like this:

dosomething();

Finally, the body goes at the bottom, and will look something like this:

void dosomething() {
    //does something
    somethingfoo = true;
  }

An example, put together

This is what the script will look like when you put everything together:

Show/Hide < code block hidden >
import "std.zh"

//global variables go here
bool somethingfoo;

global script onstart {
  void run() {
   
    //one time things go here
   
    while(true) {
     
      //function calls go here
     
      dosomething();
     
      Waitframe();
    }
  }
 
  //functions go here
  void dosomething() {
    //does something
    somethingfoo = true;
  }
}

Why do it this way?

Because there can only be one OnStart script, multiple "functions" must be rolled into a single script. By keeping the main body of the script (the run() function) clean, and isolating the different features into functions, it becomes easier to add and remove the individual features. For those writing scripts, you don't have to worry about polution from other scripts mucking your script's variables up.

I would provide a real working example of a global script, but that's beyond the scope of this tutorial. Feel free to browse the Script Library, though.