Casting is the conversion of data types for compatibility within methods. For example, a list is cast to a string whenever it is used as a string input. So joining a list [a, b, c] to "... is a list" will return the string "a b c ... is a list".

Rules

Casting in Scratch follows the following rules:

Casting Rules String input Number input
Strings String:
"abc"
"abc" 0
String:
"123"
"123" 123
Numbers Number:
123
"123" 123
Booleans Boolean:
true
"true" 1
Boolean:
false
"false" 0
Lists List:
["a", "b", "c"]
"abc" 0
List:
["a", "b", "c", "are the letters"]
"a b c are the letters" 0
List:
["1", "2", "3"]
"123" 123
List:
[1, 2, 3]
"1 2 3" 0
List:
[1, 22, 3]
"1 22 3" 0
List:
["3", ".", "1", "4"]
"3.14" 3.14
List:
[3, ".", 1, 4]
"3 . 1 4" 0
List:
[]
"" 0

See Also

This article or section documents the current version of Scratch (version 2.0). For this article in Scratch 1.4, see Casting (1.4).