Discuss Scratch
- Discussion Forums
- » Suggestions
- » Boolean variables.
- Splashmasters
-
19 posts
Boolean variables.
Variables are used for a lot of stuff. Especially numbers. But wouldn't it be fun to have an standard boolean? So for example: An variable with the name “Is Cat” would normally say “0”, but that doesn't make any sense because it is a yes or no question, not a numberic question. So add an checkbox named “Boolean” and a description saying “Instead of numbers, uses true or false.” This, when paired with on cloud, should be used as extra or less score on the leaderboard, thus should have an other variable attached to it with cloud enabled too and an number adding or subtracting the score. That way, code can be shortened and new players have ease with variables.
Edit: Yes, I know that you could already do so, but… it's just shortening code and makes it default “false”
Here is an example for code before:
Edit: Yes, I know that you could already do so, but… it's just shortening code and makes it default “false”
Here is an example for code before:
(☁ example) is equal to 50, for your knowledge
set (boolean) to [true]
if <(boolean) is true> then
increase (☁ example) by 100
Just saying something for the values.
end
[scratchblocks]
The value of example would be 150
Now here the same output but then with my suggestion
Boolean has been linked with example and has been selected with 100. Example is still 50.
Also for some ungodly reason it won't change to normal text and shows a block saying "scratchblock"
((it should be hidden...))
[scratchblocks]
toggle (boolean)
OR we could do
flip (boolean) to [true] For your knowlege, for some ungodly reason, it won't change to a dropdown whatever I do.
[scratchblocks]
And the result is that example is equal to 150, shortening the code to ONE block.
So overall this is to shorten code.
Last edited by Splashmasters (June 16, 2024 14:52:55)
- hydrofungus
-
1000+ posts
Boolean variables.
Doesn’t the operator blocks already do this? (The <, > and = ones)
You can do like, for example 0 is false and 1 is true
You can do like, for example 0 is false and 1 is true
when green flag clicked
set [variable v] to [0]
if <touching [smth v] ?> then
set [variable v] to [1]
end
when green flag clicked
if <(variable) = [1]> then
say [hello world!] for (2) secs
end
Last edited by hydrofungus (June 15, 2024 09:53:07)
- jmdzti_0-0
-
1000+ posts
Boolean variables.
No support.
This has an easy workaround:
This has an easy workaround:
<(foo) = [true]>
- julmik6478
-
500+ posts
Boolean variables.
Support, beacuse it can expand my custom blocks pack named backblocks. Also I know workaround:
set [foo v] to <boolean>
<(foo) = [true]>
- hydrofungus
-
1000+ posts
Boolean variables.
my custom blocks pack named backblocks. Also I know workaround:That workaround doesn’t exist? Support, beacuse it can expandset [foo v] to <boolean>
<(foo) = [true]>
- medians
-
1000+ posts
Boolean variables.
But it does?my custom blocks pack named backblocks. Also I know workaround:That workaround doesn’t exist? Support, beacuse it can expandset [foo v] to <boolean>
<(foo) = [true]>
Anyways, already suggested:
https://scratch.mit.edu/discuss/post/59944/
- Foldy_TPOT
-
100+ posts
Boolean variables.
No support.
if <condition::grey> then
set [boolean variable v] to [true]
else
set [boolean variable v] to [false]
end
- julmik6478
-
500+ posts
Boolean variables.
Duplicate of https://scratch.mit.edu/discuss/topic/8618/
Easier version: Doesn’t the operator blocks already do this? (The <, > and = ones)
You can do like, for example 0 is false and 1 is truewhen green flag clicked
set [variable v] to [0]
if <touching [smth v] ?> then
set [variable v] to [1]
endwhen green flag clicked
if <(variable) = [1]> then
say [hello world!] for (2) secs
end
set [variable v] to <touching [smth v] ?>
Last edited by julmik6478 (June 16, 2024 07:55:34)
- Splashmasters
-
19 posts
Boolean variables.
Yes, I already know you just can do this:
If it would be at default like this:
set [ Example] to [True]But it is at default just 0.
If it would be at default like this:
(☁ Example) = falseThen it would save some space (i think) and this could shorten code, especially for other variables
- Discussion Forums
- » Suggestions
-
» Boolean variables.