Types
ScratchScript is a strongly typed language, meaning once you assign a variable a type, it cannot be changed later. There are 5 basic types which one will frequently use during development.
Scratch also has a set of types which isn't enforced to the user, but is required for project files to be correctly loaded. Still, Scratch can be considered a weakly-typed language.
Number
The number
type is identical to that of JavaScript's/Typescript's, since that's what the Scratch3 VM uses internally.
number
represents a double-precision 64-bit binary format IEEE 754 value, which means any number between -(2^53 - 1)
and 2^53 - 1
is valid.
All of these number expressions are valid in ScratchScript:
10
10.0
-123.45
-1234
String
A string
literal can be defined via single quotes ('hi!'
) or double quotes ("hello!"
). Backticks (`hey!`
) are not supported.
To write a single quote in a string literal defined with single quotes, either replace the literal with a double-quoted one, or use \'
:
Boolean
boolean
is a type that doesn't exist in Scratch. While true
and false
keywords exist in ScratchScript, internally ScratchIR considers them strings. Still, you can define a boolean variable and use it in conditions and other places:
List
List
is the only "generic" type which can hold any other basic type inside of it. Unlike TypeScript, where arrays are defined via square brackets (type[]
), ScratchScript uses List<type>
.
Lists can also be 2-dimensional, or even 3-dimensional:
Color
color
expressions are defined in the #RRGGBB
format: