GM: Scripts

From GMpedia.org Wiki

(Redirected from GM: Script)
Jump to: navigation, search
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.

[edit] Arguments

Main article: GM: 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.

This article is a stub, please help GMpedia expand it.

[edit] Returning values

Main article: GM: 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;
 }
<code>
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 GM: Getting the number of blue pixels on the screen.

[edit] See Also

Personal tools