Discuss Scratch

mybearworld
Scratcher
1000+ posts

?-Operator [inline if-then-else]

Rendangbike2 wrote:

Futurebot5 wrote:

Zoomer_X wrote:

Duplicate. This link was mentioned before in this topic.
merge pls
Reported it to be merged
PTheGreat42
Scratcher
100+ posts

?-Operator [inline if-then-else]

MushroomMan99 wrote:

This can be workarounded easily.
if <key [space v] pressed?> then

say [Key space is pressed] for (2) secs
else
say [Key space is not pressed] for (2) secs
end
No support
Workarounds for a suggested block don`t mean that block shouldn`t be added.
Scratchperson1000000
Scratcher
500+ posts

?-Operator [inline if-then-else]

DevanWolf wrote:

We need this block:
(if<>then[]else[]::operators)
Like they have in some Scratch mods.

If the boolean in the block reports true, it reports the first value. Otherwise, if false, it reports the else value.

For an example:
when gf clicked
ask[Are you cool?]and wait
say(if<(answer)=[yes]>then[Good!]else[What!?]::operators)for(2)secs
(removed - no message)
EDIT: AND CLOSE YOUR TAGS

Last edited by Scratchperson1000000 (Feb. 24, 2021 18:57:21)

fishu4
Scratcher
100+ posts

?-Operator [inline if-then-else]

PH-zero wrote:

(#9)
bumb
Bumb?
jackson49
Scratcher
1000+ posts

?-Operator [inline if-then-else]

Bump
historical_supa
Scratcher
1000+ posts

?-Operator [inline if-then-else]

Support, the workaround is kinda time-consuming.
IdkbutprobablyAmogus
Scratcher
100+ posts

?-Operator [inline if-then-else]

20btheilmanngohr wrote:

So wait, what's the problem with
when green flag clicked
ask [Are you cool?] and wait
if <> then
say [Good!] for (2) secs
else
say [What!?] for (2) secs
end
You didn't say anything about how the boolean could be useful, you just said how it works and what it does. Unless there are some pros or cons listed, I think I'll stick to -1
when green flag clicked::operators
move (10) steps::operators
Quantum-Cat
Scratcher
1000+ posts

?-Operator [inline if-then-else]

My opinion is on between in this. On one hand, this is efficient and really useful, decreasing the need for variables and if-else stacks every time you want to do something similar, and can be seen in other programming languages (e.g. the ternary ?: operator). But does everything in other languages that can simplify code be implemented? In that case, there are a lot of things that can be put, but would clutter the area. Scratch, being a drag-and-drop language, aims to offers what is needed for most users to do what they want, with a limited capacity for blocks.
windows-11-pro
Scratcher
100+ posts

?-Operator [inline if-then-else]

Paddle2See wrote:

(#2)
Basically, an in-line if-then-else construct. Handy, certainly, but nothing that can't be done fairly well with other blocks. For instance, on your last example, you could do the same thing with this:

if <(pick random (1) to (2)) = [1]> then
set [value v] to [1]
else
set [value v] to [-1]
end

Perhaps even more easily understood than the in-line version.
this is better (in one line)
set [value v] to ((-1) + (<(pick random (1) to (2)) = [1]> * (2)
medians
Scratcher
1000+ posts

?-Operator [inline if-then-else]

Bobmr2024
Scratcher
100+ posts

?-Operator [inline if-then-else]

medians wrote:


how did you get the block?
TheCreatorOfUnTV
Scratcher
1000+ posts

?-Operator [inline if-then-else]

Bobmr2024 wrote:

medians wrote:


how did you get the block?
Judging by how it looks, I think from Snap!
medians
Scratcher
1000+ posts

?-Operator [inline if-then-else]

TheCreatorOfUnTV wrote:

Bobmr2024 wrote:

medians wrote:


how did you get the block?
Judging by how it looks, I think from Snap!
No, that's Scratch 2.0, 2.0 blocks look different from Snap and 1.x.

Last edited by medians (July 8, 2024 20:31:05)

TheCreatorOfUnTV
Scratcher
1000+ posts

?-Operator [inline if-then-else]

medians wrote:

TheCreatorOfUnTV wrote:

Bobmr2024 wrote:

medians wrote:


how did you get the block?
Judging by how it looks, I think from Snap!
No, that's Scratch 2.0.
Oh wait, Snap! doesn't have a light mode (just like Scratch 3 doesn't have an official dark mode.)
Alright then, how DID you get that block?
medians
Scratcher
1000+ posts

?-Operator [inline if-then-else]

TheCreatorOfUnTV wrote:

medians wrote:

TheCreatorOfUnTV wrote:

Bobmr2024 wrote:

medians wrote:


how did you get the block?
Judging by how it looks, I think from Snap!
No, that's Scratch 2.0.
Oh wait, Snap! doesn't have a light mode (just like Scratch 3 doesn't have an official dark mode.)
Alright then, how DID you get that block?
I mean, there's kind of a light mode if you turn on flat design (I do not like how that looks though), so:
I used Edit Block Colors and used an old version of 2.0, and then created a list like that using a bug that appeared in earlier versions of 2.0, where block specs would show up if you put them in list names, custom block names, and variable names:
https://en.scratch-wiki.info/wiki/Argument#Use_in_block_specs_(Scratch_2.0)

Last edited by medians (July 8, 2024 20:36:06)

starlightsparker
Scratcher
1000+ posts

?-Operator [inline if-then-else]

Isn’t that just
if <> then 



else

end
medians
Scratcher
1000+ posts

?-Operator [inline if-then-else]

starlightsparker wrote:

Isn’t that just
if <> then 

else

end
It is basically this, but this is easier since you do not have to create a result variable or anything, and can fit in reporter inputs (also, this has been used in other places too):
if <bool::grey> then
set [result v] to (first result::grey)
else
set [result v] to (second result::grey)
end
starlightsparker
Scratcher
1000+ posts

?-Operator [inline if-then-else]

medians wrote:

starlightsparker wrote:

Isn’t that just
if <> then 

else

end
It is basically this, but this is easier since you do not have to create a result variable or anything, and can fit in reporter inputs (also, this has been used in other places too):
if <bool::grey> then
set [result v] to (first result::grey)
else
set [result v] to (second result::grey)
end
Is there a clear benefit to fitting in Boolean inputs? In what situation would it be needed? /gen
medians
Scratcher
1000+ posts

?-Operator [inline if-then-else]

starlightsparker wrote:

Is there a clear benefit to fitting in Boolean inputs? In what situation would it be needed? /gen
To prevent multiple if statements, and if there are block inputs in the future, it could be used for that too.
Also, what do you mean by boolean?? You mean reporter??

Last edited by medians (July 8, 2024 21:18:41)

ajskateboarder
Scratcher
1000+ posts

?-Operator [inline if-then-else]

starlightsparker wrote:

medians wrote:

starlightsparker wrote:

Isn’t that just
if <> then 

else

end
It is basically this, but this is easier since you do not have to create a result variable or anything, and can fit in reporter inputs (also, this has been used in other places too):
if <bool::grey> then
set [result v] to (first result::grey)
else
set [result v] to (second result::grey)
end
Is there a clear benefit to fitting in Boolean inputs? In what situation would it be needed? /gen
Yes because code can be made more concise (usually) while still being readable (in a lot of cases)

Powered by DjangoBB