In other languages

Help the wiki!

The Scratch Wiki is made by and for Scratchers. Do you want to contribute?

Learn more about joining as an editor!

See discussions in the Community Portal

Casting

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, 22, 3]
"1 22 3" 0
List:
[3, ".", 1, 4]
"3.14" 3.14
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).
  • This page was last modified on 3 September 2014, at 22:36.