Attributes
Attributes are a way to add metadata to your code. They can be applied to functions or exist on their own.
Top-level attributes
Top-level attributes should be defined before any code is imported or any functions are created. They change the way the compiler generates some expressions and allows importing assets into the project.
useFloatEquation
@useFloatEquation(accuracy)
replaces all binary equality operations with approximate floating point number equations. This is actually a common issue when trying to compare numbers, and by enabling this attribute ScratchScript will generate abs(num1 - num2) < accuracy
instead of num1 == num2
when comparing two numbers.
unicode
@unicode
enables advanced string handling, which is superior to Scratch's, but much slower.
Natively, Scratch doesn't differentiate uppercase and lowercase letters when comparing strings, so without this attribute "a" == "A"
will return true
.
Function attributes
Function attributes are applied before defining the function and change how it behaves.
warp
Adding @warp
makes a function run without screen refresh. Generally, this means that a function will run as fast as possible, attempting to complete the whole script in one frame.
extension
@extension(type)
turns a function into a member function.
type
must be a valid type (i.e. number
, boolean
, or List<string>
).
Any function with the @extension
attribute must include at least one argument with the specified type.