FrostyCat
Redemption Seeker
Symptoms to Look For
Expand for screenshot:
For Question Askers
You are getting this error because you are using obsolete script syntax, which appear in older tutorials and reference material for GMS 2.2 or below published before 2020. If you use GML Code, you must wrap your script body using the new
If you use GML Visual, please see Slyddar's instructions for using the Define a New Function action. The rest of this article deals with GML Code.
Script Functions without Arguments
Leave the script arguments part blank, and paste the script body between the braces.
Example: Write a function
Script Functions with Arguments
If your script function takes a fixed number of arguments, name and list them between the brackets (usual variable naming rules apply), and replace their occurrences in the script body. You should no longer refer to
Example: Write a function
Script Functions with Unknown Number of Arguments
If your script function takes an unknown number of arguments, leave the script arguments part blank, and continue using
Example: Write a function
Script Functions with Trailing Optional Arguments
If your script function has some required arguments followed by a fixed number of optional arguments:
Example: Write a function
For Responders
If you see this kind of error, DO NOT respond by telling them to declare the variables in question. Teach them the new script function syntax and refer them to this helpdesk article.
Related Links
Updated 2023-12-10: Added link to Slyddar's instructions for GML Visual and new instructions for trailing optional arguments. Also retitled the article to reflect the new version numbering convention.
Expand for screenshot:
- The error is in the Create Event for object
<undefined>
. - The subject is
<unknown object>
with a variable name that's either built-in or known to be already declared. - The stack trace shows the source as something starting with
gml_GlobalScript
.
For Question Askers
You are getting this error because you are using obsolete script syntax, which appear in older tutorials and reference material for GMS 2.2 or below published before 2020. If you use GML Code, you must wrap your script body using the new
function
keyword.
GML:
function your_script_name(/* Script arguments here */) {
/* Script body here */
}
Script Functions without Arguments
Leave the script arguments part blank, and paste the script body between the braces.
Example: Write a function
d6()
that returns the result of a 6-sided die roll.Before | After |
---|---|
GML:
|
GML:
|
Script Functions with Arguments
If your script function takes a fixed number of arguments, name and list them between the brackets (usual variable naming rules apply), and replace their occurrences in the script body. You should no longer refer to
argument0
...argument15
or set up separate local variables for them.Example: Write a function
add(a, b)
that returns a+b
.Before | After |
---|---|
GML:
|
GML:
|
Script Functions with Unknown Number of Arguments
If your script function takes an unknown number of arguments, leave the script arguments part blank, and continue using
arguments
and argument_count
in the body as before.Example: Write a function
sum(...)
that returns the sum of all arguments passed into it.Before | After |
---|---|
GML:
|
GML:
|
Script Functions with Trailing Optional Arguments
If your script function has some required arguments followed by a fixed number of optional arguments:
- Name and list the required arguments between the brackets, just as you would for a script function with a fixed number of arguments.
- Name and list the optional arguments afterwards, in the form
argumentName=defaultValue
for each.
argument_count
, use argument[n]
, or set up separate local variables for arguments.Example: Write a function
draw_set_props(col, [halign], [valign])
that sets at once the font colour (required), horizontal alignment (optional), and vertical alignment (optional). The horizontal alignment should default to fa_left
, and the vertical alignment should default to fa_top
.Before | After |
---|---|
GML:
|
GML:
|
For Responders
If you see this kind of error, DO NOT respond by telling them to declare the variables in question. Teach them the new script function syntax and refer them to this helpdesk article.
Related Links
- https://help.yoyogames.com/hc/en-us/articles/360005277377
- https://www.yoyogames.com/blog/549/gamemaker-studio-2-3-new-gml-features
- https://forum.gamemaker.io/index.php?threads/dnd-platformer-tutorial-bug.85103/#post-508840 (Slyddar's instructions for GML Visual)
Updated 2023-12-10: Added link to Slyddar's instructions for GML Visual and new instructions for trailing optional arguments. Also retitled the article to reflect the new version numbering convention.
Last edited: