Workarounds
Generating Random Decimal Numbers#
random only outputs decimals if its arguments are formatted as decimals, but goboscript optimizes 1.0 to 1, turning them into integers. Pass the arguments as strings to prevent this:
say random("0.0", "1.0");
Converting Strings to Numbers#
Scratch arithmetic operators cast strings to numbers automatically. To force this in goboscript, use a string zero or empty string — the optimizer ignores these, unlike + 0:
numeric_value = string_variable + "0";
numeric_value = string_variable + "";
Simulating "Wait Until"#
Use an until loop with an empty body:
until (condition) {}
Namespacing Variables#
Use %define to alias a long unique variable name to a short name within a header,
then %undef it at the end of the header to prevent the alias from affecting later
code. Declare the variable before reading it.
The underlying variable remains accessible to other code by its full name.
After %undef, assigning private_variable = 10; declares a separate variable
named private_variable.
lib/my_module.gs
%define private_variable __my_module__private_variable
var private_variable = 0;
func get_my_variable() {
return private_variable;
}
%undef private_variable
main.gs
%include lib/my_module
proc show_my_variable {
say get_my_variable();
}
onflag {
show_my_variable;
# say private_variable; # error — alias no longer defined
}
"While" Loop Macro#
Goboscript has no while loop, but you can macro it:
%define while(CONDITION) until (not (CONDITION))
onflag {
i = 0;
while (i < 10) {
i++;
}
}