Discuss Scratch
- HTML-Fan
-
1000+ posts
Variable to boolean block
I would like to have a block like
<()::operators>or
<[]::operators>which just converts an 1 as a variable to true and 0 to false and true (string) to true (boolean) and false (string) to false (boolean). It would be useful if you want to store in a variable if something is shown or not.
Last edited by HTML-Fan (June 28, 2020 09:36:00)
- -Squiggle
-
500+ posts
Variable to boolean block
what would happen if the variable was larger than 1? I would like to have a block like<()::operators>which just converts an 1 as a variable to true and 0 to false and true (string) to true (boolean) and false (string) to false (boolean). It would be useful if you want to store in a variable if something is shown or not.
also, the block would not work, as you would be able to add other things like costume name, which would confuse things…
there is a very simple workaround which is
if <(variable) = [1]> thenI consider that workaround better, as you can choose the limit (eg. what if you wanted to know whether the variable was ‘3’, ‘2’ or ‘1’ rather than just ‘2’ or ‘1’?)
...
end
if <(variable) = [2]> then
...
end
- Maximouse
-
1000+ posts
Variable to boolean block
It would be true. Only “false”, 0, and an empty string should be considered false. what would happen if the variable was larger than 1?
- HTML-Fan
-
1000+ posts
Variable to boolean block
It should be 0 or 1 (like in C++ and other things) or “false” and “true”.
There's a simple workaround, but the = 1 doesn't look nice. If you just can use a variable as a boolean, then it's clear what it's doing.
There's a simple workaround, but the = 1 doesn't look nice. If you just can use a variable as a boolean, then it's clear what it's doing.
- HTML-Fan
-
1000+ posts
Variable to boolean block
Yes, it would be like It would be true. Only “false”, 0, and an empty string should be considered false.
if(variable)
in C++. But the String “false” is also false, since that's what you get by using
set [xyz v] to <mouse down?>
Last edited by HTML-Fan (June 28, 2020 09:17:57)
- -Squiggle
-
500+ posts
Variable to boolean block
yes. but that would still be just a more limited version of a block that you could already use… I don't see the sense in that?Yes, it would be like It would be true. Only “false”, 0, and an empty string should be considered false.
if(variable)
in C++. But the String “false” is also false, since that's what you get by usingset [xyz v] to <mouse down?>
- -Squiggle
-
500+ posts
Variable to boolean block
mmm… ok - this would be simple to use when it comes to variables, but wouldn't this still mess up when it comes to other reporter blocks? It should be 0 or 1 (like in C++ and other things) or “false” and “true”.
There's a simple workaround, but the = 1 doesn't look nice. If you just can use a variable as a boolean, then it's clear what it's doing.
- Maximouse
-
1000+ posts
Variable to boolean block
All reporter blocks work the same as variables. Also, I suggest the block to look like this:mmm… ok - this would be simple to use when it comes to variables, but wouldn't this still mess up when it comes to other reporter blocks? It should be 0 or 1 (like in C++ and other things) or “false” and “true”.
There's a simple workaround, but the = 1 doesn't look nice. If you just can use a variable as a boolean, then it's clear what it's doing.
<[true v] :: operators>You could choose “true” or “false” in the dropdown menu, or drop a reporter onto it.
- HTML-Fan
-
1000+ posts
Variable to boolean block
I store the mouse down state in a variable so I can use
if <<(mousedown)::operators> and <not <(oldmousedown)::operators>>> then
end
- HTML-Fan
-
1000+ posts
Variable to boolean block
Yes. Or just useAll reporter blocks work the same as variables. Also, I suggest the block to look like this:mmm… ok - this would be simple to use when it comes to variables, but wouldn't this still mess up when it comes to other reporter blocks? It should be 0 or 1 (like in C++ and other things) or “false” and “true”.
There's a simple workaround, but the = 1 doesn't look nice. If you just can use a variable as a boolean, then it's clear what it's doing.<[true v] :: operators>You could choose “true” or “false” in the dropdown menu, or drop a reporter onto it.
<(0)::operators>
<(1)::operators>
- -Squiggle
-
500+ posts
Variable to boolean block
How would you know which variable this is referring to? Also, I suggest the block to look like this:<[true v] :: operators>You could choose “true” or “false” in the dropdown menu, or drop a reporter onto it.
- HTML-Fan
-
1000+ posts
Variable to boolean block
I would just use 1 and 0 together with variable to boolean.
- -Squiggle
-
500+ posts
Variable to boolean block
what do you mean? I would just use 1 and 0 together with variable to boolean.
- HTML-Fan
-
1000+ posts
Variable to boolean block
There you have true and false as booleans. Alternative:<[0]::operators>
<[1]::operators>
<[false]::operators>
<[true]::operators>
- -Squiggle
-
500+ posts
Variable to boolean block
yes. but how would you know what variable this is for?There you have true and false as booleans. Alternative:<[0]::operators>
<[1]::operators><[false]::operators>
<[true]::operators>
- Maximouse
-
1000+ posts
Variable to boolean block
That would just report true or false.yes. but how would you know what variable this is for?There you have true and false as booleans. Alternative:<[0]::operators>
<[1]::operators><[false]::operators>
<[true]::operators>
- HTML-Fan
-
1000+ posts
Variable to boolean block
I don't know what you want to say.
It should just convert a number, text or variable with either to a boolean:
It should just convert a number, text or variable with either to a boolean:
<[false]::operators> //returns false
<[true]::operators> //returns true
<[0]::operators> //returns false
<[1]::operators> //returns true
set [var v] to [0]
<(var)::operators> //returns false
set [var v] to [true]
<(var)::operators> //returns true
- -Squiggle
-
500+ posts
Variable to boolean block
ah. that makes more sense. yes, it's a possible… but there are still probably some things which would need to be thought through. I don't know what you want to say.
It should just convert a number, text or variable with either to a boolean:<[false]::operators> //returns false
<[true]::operators> //returns true
<[0]::operators> //returns false
<[1]::operators> //returns true
set [var v] to [0]
<(var)::operators> //returns false
set [var v] to [true]
<(var)::operators> //returns true
- HTML-Fan
-
1000+ posts
Variable to boolean block
I would say that the only things which are false are 0 and “false” (not case-sensitive).