Parameters
Functions can take some "arguments" (the reason for the quotes is going to be mentioned later). This allows you to pass in values when calling the function the same exact way as you would pass in numbers to the builtin functions.
There's two types of arguments a function can take, which is BOOL
, and VECTOR
. BOOL
is simply a boolean; TRUE
or FALSE
. Refer to this page for an explanation of vectors.
Setting Up Parameters
To add parameters to a function, you simply use the brackets []
separated by any whitespace from the name of the function and the opening block bracket {
. In between the square brackets, add the names of the parameters, consistent with the naming of variables in general:
<FUNCS>
@click_x_times [$x] { # $x is assumed to be a vector #
@repeat [$x] {
[MB_LEFT]
}
}
Since parameters are assumed to be vectors, you can override this by using this notation:
<FUNCS>
@click_or_not [$click -> BOOL] {
@if $click {
[MB_LEFT]
}
}
Calling Parameterized Functions
To call a function that has parameters, simply provide the arguments the same way as you would to a builtin function:
<FUNCS>
@click_x_times [$x] { # $x is assumed to be a vector #
@repeat [$x] {
[MB_LEFT]
}
}
@click_or_not [$click -> BOOL] {
@if $click {
[MB_LEFT]
}
}
<MACRO>
@click_x_times [5] # Clicks `MB_LEFT` 5 times #
@click_or_not [TRUE] # Clicks `MB_LEFT` #
@click_or_not [FALSE] # Does not click `MB_LEFT` #
You can of course, also pass in a VECTOR
or a MODE
/SWITCH
, again, the same way as discussed earlier in the docs.
Since, as we mentioned earlier, functions do not get run in a "special" environment, when passing arguments you set the global variable named in the function declaration.
These parameters get automatically declared as global VECTORS
or SWITCHES
and initialized with default values of [0,0]
(in JavaScript array notation) and FALSE
respectively.
To make this clear with an example, consider this:
<FUNCS>
@set_y [$y] { # This will declare $y automatically #
# Does nothing here #
}
<MACRO>
# $y is currently 0,0 #
@set_y [5]
# $y is now 5,0 #
So, make sure to exercise caution as to not cause conflicts in the code.