Discuss Scratch
- mlcreater
-
Scratcher
1000+ posts
Variable to boolean
That's 0 too. I think that 0.0 = 0 would return true, but I'm not sure, I'll try it …

- mlcreater
-
Scratcher
1000+ posts
Variable to boolean
How about space? (“ ”)I would like to have a block likeWhat about 0.0?<[] to boolean :: operators>which would convert 0, “” and “false” into false and everything else into true.
- HTML-Fan
-
Scratcher
1000+ posts
Variable to boolean
To be honest: I pretty much don't care what happens to everything besides 0, 1, “true” and “false”.
- NxNmultiply
-
Scratcher
100+ posts
Variable to boolean
A string is an array so it's expressed by an array pointer but it's not a null pointer so it returns true:How about space? (“ ”)I would like to have a block likeWhat about 0.0?<[] to boolean :: operators>which would convert 0, “” and “false” into false and everything else into true.

- mlcreater
-
Scratcher
1000+ posts
Variable to boolean
Is that C?A string is an array so it's expressed by an array pointer but it's not a null pointer so it returns true:How about space? (“ ”)I would like to have a block likeWhat about 0.0?<[] to boolean :: operators>which would convert 0, “” and “false” into false and everything else into true.
- BosenChang
-
Scratcher
1000+ posts
Variable to boolean
why not just do this?Simply do this:when green flag clicked
forever
if <(jumping?) = [1]> then
jump :: custom ::
end
end
when gf clicked
forever
if <(jumping?) = <<> and <>>> then
jump :: grey
wait until <(jumping?) = <not <>>>
end
- hedgehog_blue
-
Scratcher
1000+ posts
Variable to boolean
Scratch already converts values when using the equals operator. If you do this:
All other values are not equal to the true or false boolean values:
So you can use either of these as the workaround, depending on how you want other values to behave:
set [true v] to <[0] = [0]> //create a "true" variable with the value true (not the word "true," but the boolean value true)The numbers 1 and 0 cause the boolean to convert to 1 or 0, allowing them to be compared. The words “true” or “false” cause the boolean to convert to text as well, allowing them to be compared.
<[true] = (true)> //true
<[false] = (true)> //false
<[1] = (true)> //true
<[0] = (true)> //false
All other values are not equal to the true or false boolean values:
set [true v] to <[0] = [0]>So you can use this behavior to choose if you want all other values (values other than true, false, the word “true,” the word “false,” 1, and 0) to be true or false:
set [false v] to <[0] = [1]>
<[something else] = (true)> //false
<[something else] = (false)> //false
<[something else] = (true)> //false
<not <[something else] = (false)>> //true
So you can use either of these as the workaround, depending on how you want other values to behave:
<(input::custom) = <[0] = [0]>> //other values result in false(I didn't use the true/false variables for the final workaround, but you can use them if you want to make your code more clear with the disadvantage of having more variables)
<not <(input::custom) = <[0] = [1]>>> //other values result in true
- mlcreater
-
Scratcher
1000+ posts
Variable to boolean
So you can use either of these as the workaround, depending on how you want other values to behave:But the second one (which is what this topic is asking for) converts “” to true, while this topic wants “” to be false<(input::custom) = <[0] = [0]>> //other values result in false
<not <(input::custom) = <[0] = [1]>>> //other values result in true
- hedgehog_blue
-
Scratcher
1000+ posts
Variable to boolean
Yeah, the way the equals block works is it converts the boolean to a number/string rather than converting the number/string to a boolean, so there can be only one corresponding boolean value for each type. Because only boolean reporters can be put in boolean inputs (without hacks) we can't actually use the official boolean conversion that scratch has. This means that if you want empty strings as well, then you'll just have to do something like this:So you can use either of these as the workaround, depending on how you want other values to behave:But the second one (which is what this topic is asking for) converts “” to true, while this topic wants “” to be false<(input::custom) = <[0] = [0]>> //other values result in false
<not <(input::custom) = <[0] = [1]>>> //other values result in true
<<original workaround::grey> and <not <(input::custom) = []>>>