Game Development Reference
In-Depth Information
Returning a value
The final part of a script is returning a value. This is done using the return function fol-
lowed by the number, string, or variable you wish to return.
Being able to return a value from a script allows the script to be used completely like a nor-
mal function. We can execute a piece of code and then save the result in a variable for later
use by the object.
Let's apply this to our add script. To do this, all we have to do is replace the
show_message function with a return function, followed by the answer variable.
This is how it looks in GameMaker:
That's it for our add script. We can now execute the script from within an object with any
number we choose, and have the result returned and saved in a variable.
Let's go to our object and save this value to a variable, and then show a message with the
result.
Search WWH ::




Custom Search