Discuss Scratch

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

1Draven wrote:

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

NeonG4 wrote:

(#2)

1Draven wrote:

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
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?
NeonG4
Scratcher
1000+ posts

About variables

1Draven wrote:

NeonG4 wrote:

(#2)

1Draven wrote:

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
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?
That would be evaluated as true.
1Draven
Scratcher
100+ posts

About variables

legendary34678 wrote:

(#3)
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.
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
1Draven
Scratcher
100+ posts

About variables

Sorry about the grammar
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

legendary34678 wrote:

(#8)
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.
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?
medians
Scratcher
1000+ posts

About variables

don't tell the scratch team about my hacked blocks


1Draven
Scratcher
100+ posts

About variables

medians wrote:

(#10)
don't tell the scratch team about my hacked blocks



ok
chriscreators14
Scratcher
500+ posts

About variables

medians wrote:

don't tell the scratch team about my hacked blocks


this is the 1st time I have seen medians necropost
medians
Scratcher
1000+ posts

About variables

chriscreators14 wrote:

this is the 1st time I have seen medians necropost
but it was relevant and I made that post on the day the topic was created LOL (they asked about the 57 thingy)

Powered by DjangoBB