-
Notifications
You must be signed in to change notification settings - Fork 48
Using #args magic
GMS≥2.3 note: This GMEdit feature has been superseded by native named argument support and ??= operator.
#args
magic allows to largely streamline the process of writing code that assigns arguments into temporary variables.
Upon saving, #args
line is expanded into equivalent GML code.
Upon loading, GML code in matching format is collapsed into an #args
line.
The feature can be enabled/disabled in preferences.
Examples of use follow
If all arguments must be specified, write them as a comma-separated list, much like with var
:
#args a, b
which will produce
var a = argument0, b = argument1;
If some of the arguments are optional and should be replaced by a default value, you can specify that by assigning a value to the named argument - again, much like with var
syntax.
One restriction here is that the values may not span multiple lines.
#args a, b = 4
which will produce
var a = argument[0];
var b; if (argument_count > 1) b = argument[1]; else b = 4;
on GMS1 and
var a = argument[0];
var b = argument_count > 1 ? argument[1] : 4;
on GMS2.
If you specifically want an argument to default to undefined
if not provided, you can prefix it's name with a question mark ?
instead of writing arg = undefined
:
#args a, ?b
which will produce
var a = argument[0];
var b; if (argument_count > 1) b = argument[1]; else b = undefined;
on GMS1 and
var a = argument[0];
var b = argument_count > 1 ? argument[1] : undefined;
on GMS2.
If you intend to handle some of the arguments yourself (such as with arbitrary number of trailing arguments), you can tell #args
to use argument[#]
instead of argument#
by leaving a comma in the end of the arguments-list:
#args a,
which will produce
var a = argument[0];
- Smart auto-completion
- Types
- JSDoc tags (incl. additional ones)
- @hint tag (mostly 2.3)
- `vals: $v1 $v2` (template strings)
- #args (pre-2.3 named arguments)
- ??= (for pre-GM2022 optional arguments)
- ?? ?. ?[ (pre-GM2022 null-conditional operators)
- #lambda (pre-2.3 function literals)
- => (2.3+ function shorthands)
- #import (namespaces and aliases)
- v:Type (local variable types)
- #mfunc (macros with arguments)
- #gmcr (coroutines)