Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » About variables
- 1Draven
-
Scratcher
100+ posts
About variables
If I make a variable read as true or false will it read as one or zero internally?
- NeonG4
-
Scratcher
1000+ posts
About variables
If I make a variable read as true or false will it read as one or zero internally?A variable can store anything, you could make it store true or false, or one and zero.
This however:
set [foo v] to <[1] < [2]> // will set foo to "true"but
((foo) + (x)) // will set foo to 1 or 0 + x, where 1 is true and 0 is false
Last edited by NeonG4 (June 5, 2023 19:26:29)
- legendary34678
-
Scratcher
1000+ posts
About variables
If you set a variable to “true” then it will be saved as “true” internally. However, there is a neat trick you can do with lists. You can put list items into boolean slots. So, if you set a list item to 1, it will be interpreted as True in an if loop. If it's 0, it'll be interpreted as False.
- 1Draven
-
Scratcher
100+ posts
About variables
(#2)i meant what would happen if I literally set a variable let's say A to true not by using a boolean in its place but by literally typing the word true will it read as one internally?If I make a variable read as true or false will it read as one or zero internally?A variable can store anything, you could make it store true or false, or one and zero.
This however:set [foo v] to <[1] < [2]> // will set foo to "true"but((foo) + (x)) // will set foo to 1 or 0 + x, where 1 is true and 0 is false
- NeonG4
-
Scratcher
1000+ posts
About variables
That would be evaluated as true.(#2)i meant what would happen if I literally set a variable let's say A to true not by using a boolean in its place but by literally typing the word true will it read as one internally?If I make a variable read as true or false will it read as one or zero internally?A variable can store anything, you could make it store true or false, or one and zero.
This however:set [foo v] to <[1] < [2]> // will set foo to "true"but((foo) + (x)) // will set foo to 1 or 0 + x, where 1 is true and 0 is false
- 1Draven
-
Scratcher
100+ posts
About variables
(#3)oh so if I put in true as an item in a list it would read as one internally because 1 reads as true internally because if you put booleans in operators like let's say one equals zero - one equals one it would = -1
If you set a variable to “true” then it will be saved as “true” internally. However, there is a neat trick you can do with lists. You can put list items into boolean slots. So, if you set a list item to 1, it will be interpreted as True in an if loop. If it's 0, it'll be interpreted as False.
- legendary34678
-
Scratcher
1000+ posts
About variables
Scratch uses Javascript. In Javascript, All values count as true except for ones that count as False. Values that count as false are as follows: 0, -0, 0n, “” (blank value), null, undefined, and NaN.
- 1Draven
-
Scratcher
100+ posts
About variables
(#8)so you're telling me if I had put 57 as one of the items in the list if I checked for that item in the list it would read as true?
Scratch uses Javascript. In Javascript, All values count as true except for ones that count as False. Values that count as false are as follows: 0, -0, 0n, “” (blank value), null, undefined, and NaN.
- chriscreators14
-
Scratcher
500+ posts
About variables
don't tell the scratch team about my hacked blocksthis is the 1st time I have seen medians necropost
- medians
-
Scratcher
1000+ posts
About variables
this is the 1st time I have seen medians necropostbut it was relevant and I made that post on the day the topic was created LOL (they asked about the 57 thingy)
- Discussion Forums
- » Help with Scripts
-
» About variables







