Variables#
Declaration/Assignment#
The first assignment to a variable is considered its declaration.
Variables for all sprites#
If a variable is assigned to in stage.gs
, it will be declared as for all sprites.
Variables for this sprite only#
Variables are by-default declared as for this sprite only. If you want to declare a
variable for all sprites, assign to it in stage.gs
.
Local Variables#
Local variables are accessible only within the procedure they are declared in.
The first assignment with the local
keyword will declare a local variable, all further
uses of the variable will refer to the local variable. If a normal variable with the same
name exists, it will be shadowed.
In the compiled Scratch project, the variable x
will be named as my_procedure:x
.
Note
Local variables will have undefined behavior if the procedure is recursive, or is NOT a run-without-screen-refresh procedure.
Compound Assignment#
Operator | Implementation |
---|---|
x++; |
|
x--; |
|
x += y; |
|
x -= y; |
|
x *= y; |
|
x /= y; |
|
x //= y; |
|
x %= y; |
|
x &= y; |