Discuss Scratch
- Discussion Forums
- » Suggestions
- » "if () then () else ()" control block.
- cs293450
-
100+ posts
"if () then () else ()" control block.
(if <> then [] else [])If the condition is true, reports in the first slot, if not, reports in the second slot.
- alexphan
-
1000+ posts
"if () then () else ()" control block.
define if <condition> then [1] else [2]
if <condition :: custom args> then
set [out v] to (1 :: custom args)
else
set [out v] to (2 :: custom args)
- DaSpudLord
-
1000+ posts
"if () then () else ()" control block.
^^^define if <condition> then [1] else [2]
if <condition :: custom args> then
set [out v] to (1 :: custom args)
else
set [out v] to (2 :: custom args)
Semi-support.
- da-maker
-
100+ posts
"if () then () else ()" control block.
That isn't supposed to be a control block?(if <> then [] else [])If the condition is true, reports in the first slot, if not, reports in the second slot.
(if <> then [] else []:: operators)
- matey1234
-
1000+ posts
"if () then () else ()" control block.
That's not control, that's operators ;pThat isn't supposed to be a control block?(if <> then [] else [])If the condition is true, reports in the first slot, if not, reports in the second slot.(if <> then [] else []:: operators)
(if <> then [] else []:: control)^ This is control.
Also, this ^^^^^^define if <condition> then [1] else [2]
if <condition :: custom args> then
set [out v] to (1 :: custom args)
else
set [out v] to (2 :: custom args)
Semi-support.
- Dragonboy105
-
53 posts
"if () then () else ()" control block.
It should be operators because operators is logic as well.And also controls has no reporters and would no be right. +Semi-Support
- brainstorm101
-
1000+ posts
"if () then () else ()" control block.
This is literally the exact same thing as the if then else block that is currently in Scratch, no support.(if <> then [] else [])If the condition is true, reports in the first slot, if not, reports in the second slot.
- pvz_pro
-
500+ posts
"if () then () else ()" control block.
no support
if <> then
set [report v] to [0]
else
set [report v] to [1]
end
- alexphan
-
1000+ posts
"if () then () else ()" control block.
if <...> then
...
else
...
end
You just gave a workaround to your own suggestion…? xD
- da-maker
-
100+ posts
"if () then () else ()" control block.
That's not control, that's operators ;pThat isn't supposed to be a control block?(if <> then [] else [])If the condition is true, reports in the first slot, if not, reports in the second slot.(if <> then [] else []:: operators)(if <> then [] else []:: control)^ This is control.
I know. Read carefully.
"That isn't supposed to be a control block?"
- ipaddude
-
100+ posts
"if () then () else ()" control block.
idk
it would seem kinda cool
it's built into javascript and probably wouldn't be very hard to implement ()
maybe it could be like this
ik it would be confusing to new scratchers but they wouldnt even need to touch it
it's just a convenient shorthand
it would seem kinda cool
it's built into javascript and probably wouldn't be very hard to implement (
some_boolean?"the boolean is true":"the boolean is false"
maybe it could be like this
(if <some condition::operators> then [value 1] otherwise [value 2]::operators)
ik it would be confusing to new scratchers but they wouldnt even need to touch it
it's just a convenient shorthand
- sportfan999
-
1000+ posts
"if () then () else ()" control block.
Here's a helpful workaround:
define if <some condition> then (value1)otherwise(value2)
if <condition::custom> then
set [var v] to (value1::custom)
else
set [var v] to (value2::custom)
- ipaddude
-
100+ posts
"if () then () else ()" control block.
that would work well if scratch made functions with return values Here's a helpful workaround:define if <some condition> then (value1)otherwise(value2)
if <condition::custom> then
set [var v] to (value1::custom)
else
set [var v] to (value2::custom)
- MDCCCLXVII
-
1000+ posts
"if () then () else ()" control block.
Work-aroundable in Scratch, as a stack block:(if <> then [] else [] :: operators)
define if <test> then (true) else (false)This block is included in Snap! and some Scratch modifications.
if <test> then
set [result v] to (true)
else
set [result v] to (false)
end
- gosoccerboy5
-
1000+ posts
"if () then () else ()" control block.
You can also directly build it into the code, too, instead of making a custom block.
Also duplicate topic? Not sure if there's an older one
Also duplicate topic? Not sure if there's an older one
- ipaddude
-
100+ posts
"if () then () else ()" control block.
good point You can also directly build it into the code, too, instead of making a custom block.
Also duplicate topic? Not sure if there's an older one
- Ihatr
-
1000+ posts
"if () then () else ()" control block.
To be honest, the workaround is incredibly easy to understand and use, so I don't think a new block is needed for something as simple as this.
- Greg8128
-
500+ posts
"if () then () else ()" control block.
Work-aroundable in Scratch, as a stack block:(if <> then [] else [] :: operators)define if <test> then (true) else (false)This block is included in Snap! and some Scratch modifications.
if <test> then
set [result v] to (true)
else
set [result v] to (false)
end
Not a workaround. An essential feature of the ternary operator is that it only evaluates the return value that needs to be evaluated. This feature would be necessary if Scratch could have recursive reporters, but even without that it would be nice as an optimization.
- Discussion Forums
- » Suggestions
-
» "if () then () else ()" control block.