YoYo Games Wiki

Scripts

From YoYoGames Wiki

Game Maker Scripts are used in Game Maker to execute code. A Game Maker script is basically a function, capable of taking arguments in, and returning a certain return value.

The advantage of scripts over regular pieces of code is that they could be performed more than once, saving file size, memory, and also making the code simpler to read, understand, and edit.

Arguments

Main article: Arguments

A Game Maker Argument is a variable that could be written in scripts that would be replaced by the value defined when calling the script. For example, if the script named script0 contains the following:

foo=argument0;

And this code was entered in an object:

script0(49);

Then, Game Maker will assign the real number 49 to the variable foo.

A script can have up to 16 arguments, from argument0 through argument15. Any arguments not passed to the script will be 0.

Returning values

Main article: return

The return assignment in Game Maker is used in scripts so that the script would return a value. Suppose a script is made to calculate the number of blue pixels on the screen, how would the programmer use that script to actually use that number? The code should look like this

blue_pixels=0;

 if current_pixel_color=c_blue
 {
  blue_pixels+=1;
 }

return blue_pixels;

Now, a user could use the script get_bluepixels to find the number of blue pixels on the screen, like this:

Number=get_bluepixels();
show_message(string(Number));
Note: to see the actual code for getting the number of blue pixels in Game Maker, see Getting the number of blue pixels on the screen.

See Also