GM: Scripts
From GMpedia.org Wiki
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.
[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.


