Discuss Scratch
- Discussion Forums
- » Suggestions
- » "if () then () else ()" control block.
- cs293450
-
Scratcher
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
-
Scratcher
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
-
Scratcher
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
-
Scratcher
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
-
Scratcher
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
-
Scratcher
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
-
Scratcher
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
-
Scratcher
500+ posts
"if () then () else ()" control block.
no support
if <> then
set [report v] to [0]
else
set [report v] to [1]
end
- alexphan
-
Scratcher
1000+ posts
"if () then () else ()" control block.
if <...> then
...
else
...
end
You just gave a workaround to your own suggestion…? xD
- da-maker
-
Scratcher
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
-
Scratcher
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
-
Scratcher
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
-
Scratcher
100+ posts
"if () then () else ()" control block.
Here's a helpful workaround:that would work well if scratch made functions with return valuesdefine 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
-
Scratcher
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
-
Scratcher
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
-
Scratcher
100+ posts
"if () then () else ()" control block.
You can also directly build it into the code, too, instead of making a custom block.good point
Also duplicate topic? Not sure if there's an older one
- Ihatr
-
Scratcher
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
-
Scratcher
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.














