Discuss Scratch

PH-zero
Scratcher
100+ posts

?-Operator [inline if-then-else]

Hey

Java has a very usefull operator,
it look like this:

int value = (playerAlive?1:0);

in Scratch it would probably look like this:

(if <> then [] else [] ::operators) 
set [value v] to (if <[1] = [2]> then [true!] else [false...] ::operators)
value would be set to 5 because 1=/=2

A possible use:
istead of
set [value v] to (((pick random (0) to (1))-(0.5))*(2))
to get 1 or -1 you can just use
set [value v] to (if <(pick random (0) to (1))=(1)> then [1] else [-1] ::operators) //I also think that this is way more legible

Any thoughts?

Last edited by Paddle2See (Feb. 22, 2021 11:16:10)


Ever wanted to rotate the stage? Or to
go to x:() y:() z:() ::custom
Click me!
Paddle2See
Scratch Team
1000+ posts

?-Operator [inline if-then-else]

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.

Scratch Team Member, kayak and pickleball enthusiast, cat caregiver.

This is my forum signature! On a forum post, it is okay for Scratchers to advertise in their forum signature. The signature is the stuff that shows up below the horizontal line on the post. It will show up on every post I make.
(credit to Za-Chary)



;
PH-zero
Scratcher
100+ posts

?-Operator [inline if-then-else]

Paddle2See wrote:

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.
in-line if-else, wow that describes it very well
Of course you're right the only benefit seems to be that it would be “nice to have”.
But that example is pretty simple, imagine you have a huge algorythm and now you have to break it up into
an if-else. There are now 2 huge algorythms with only one little difference in them.

Last edited by PH-zero (March 30, 2014 18:08:22)


Ever wanted to rotate the stage? Or to
go to x:() y:() z:() ::custom
Click me!
ProdigyZeta7
Scratcher
1000+ posts

?-Operator [inline if-then-else]

A little trick I learned with the booleans is that you can turn them into numbers:
define <condition> is true? yes: (value1) no: (value2)
set [value v] to (((value1) * <condition>) + ((value2) * <not<condition>>))



PH-zero
Scratcher
100+ posts

?-Operator [inline if-then-else]

ProdigyZeta7 wrote:

A little trick I learned with the booleans is that you can turn them into numbers:
define <condition> is true? yes: (value1) no: (value2)
set [value v] to (((value1) * <condition>) + ((value2) * <not<condition>>))
Yeah I also found that really cool
But you can't use this solution “in-line”
aaaaaaaand you can't multiply strings with 0 or 1 because that always gives you 0

Last edited by PH-zero (Sept. 9, 2014 20:12:15)


Ever wanted to rotate the stage? Or to
go to x:() y:() z:() ::custom
Click me!
rolledpie41
Scratcher
58 posts

?-Operator [inline if-then-else]

PH-zero wrote:

ProdigyZeta7 wrote:

A little trick I learned with the booleans is that you can turn them into numbers:
define <condition> is true? yes: (value1) no: (value2)
set [value v] to (((value1) * <condition>) + ((value2) * <not<condition>>))
Yeah I also found that really cool
But you can't use this solution “in-line”
aaaaaaaand you can't multiply strings with 0 or 1 because that always gives you 0
(<>true? yes:[] no: []) //category=operators
Mabye like this.
if <...> then [1] else [2] :: operators reporter

rolledpie41
Scratcher
58 posts

?-Operator [inline if-then-else]

BuMp

spgame05
Scratcher
100+ posts

?-Operator [inline if-then-else]

Support!
if <> is true, return [] else return [] :: control reporter
PH-zero
Scratcher
100+ posts

?-Operator [inline if-then-else]

bumb

Ever wanted to rotate the stage? Or to
go to x:() y:() z:() ::custom
Click me!
scimonster
Scratcher
1000+ posts

?-Operator [inline if-then-else]

rolledpie41 wrote:

PH-zero wrote:

ProdigyZeta7 wrote:

A little trick I learned with the booleans is that you can turn them into numbers:
define <condition> is true? yes: (value1) no: (value2)
set [value v] to (((value1) * <condition>) + ((value2) * <not<condition>>))
Yeah I also found that really cool
But you can't use this solution “in-line”
aaaaaaaand you can't multiply strings with 0 or 1 because that always gives you 0
(<>true? yes:[] no: []) //category=operators
Mabye like this.
if <...> then [1] else [2] :: operators reporter
Long suggested, and i've always supported, specifically with this wording.

Retired Community Moderator
BTW, i run Google Chrome 41.0.2272.101 on a Linux system - Ubuntu 14.04. NEW: iPad 4th gen. w/retina.

418 I'm a teapot (original - to be read by bored computer geeks)
THE GAME (you just lost)
; THE SEMICOLON LIVES ON IN OUR SIGS
DevanWolf
Scratcher
100+ posts

?-Operator [inline if-then-else]

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

Online YouTube Poop Generator is Here! | SimTunes! | Bring Back Backdrop Scroll Blocks! | New Scratch Blocks! | Scratch Soundfont! | Important MIDI Converter!

Please check out those cool games that you will like! Click a game! Any game!
when(mouse y)>(150)
repeat until <(programmers::extension)>(150)>
delete this cap::control cap
end
delete this limit::control cap
Please help Scratch Team remove the 150px Signature Height Cap!
Mrcomputer1
Scratcher
500+ posts

?-Operator [inline if-then-else]

+1

My Profile / My User Page / My Talk Page
——————–
Progress bar to 1000+ Posts - Image might not be up to date

——————–
My browser / operating system: Windows NT 10.0 (Windows 11 - 22H2), Firefox 122.0b4
——————–
My ScratchX Extensions——–If you like this post, give me an internet!——–Sharp Scratch Mod
20btheilmanngohr
Scratcher
100+ posts

?-Operator [inline if-then-else]

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

You can visit my profile here.
 
when green flag clicked ::category operators
display [link v] [http://scratch.mit.edu/users/20btheilmanngohr/] ::extension
display [text v] [20btheilmanngohr] ::extension
display [text v] [always striving for excellence!] ::extension

MegaApuTurkUltra
Scratcher
1000+ posts

?-Operator [inline if-then-else]

Regular programming (most languages) has the lazy if-else statement:
derp = (five > 5) ? 5 : 6;
// set derp to 5 if five > 5, or 6 otherwise
It's great for lazy people like me who don't like typing more than necessary.

I think Scratch should have this as well because dragging blocks is annoying. I mean why do you think I made ApuC?
So I support. I mean Scratch already has lazy things like
<loud?>
// same as
<(loudness) > (30)>
so I don't see why it can't have this as well.

$(".box-head")[0].textContent = "committing AT crimes since $whenever"
stickfiregames
Scratcher
1000+ posts

?-Operator [inline if-then-else]

Support.










If you can read this, my signature cubeupload has been eaten by an evil kumquat!




or you just used Inspect Element, you hacker

;
PH-zero
Scratcher
100+ posts

?-Operator [inline if-then-else]

Duplikate, I suggested the same a while ago:
http://scratch.mit.edu/discuss/topic/33995/?page=1#post-286812

And support of course

Ever wanted to rotate the stage? Or to
go to x:() y:() z:() ::custom
Click me!
themusicmanooo
Scratcher
69 posts

?-Operator [inline if-then-else]

you could make a block of it in more blocks
if <> then [] else []
define if (boolean) then (string) else (string)
if <(boolean) = [true]> then
say [good]
else
say [WHAT!]
end
and wow that teached me how to make if then else in more blocks


when [Programming v] key pressed
Science, PHP, C++, C, Java, VBS, Batch and JavaScript
themusicmanooo
Scratcher
69 posts

?-Operator [inline if-then-else]

well i kind of support but this is great


when [Programming v] key pressed
Science, PHP, C++, C, Java, VBS, Batch and JavaScript
stickfiregames
Scratcher
1000+ posts

?-Operator [inline if-then-else]

themusicmanooo wrote:

you could make a block of it in more blocks
if <> then [] else []
define if (boolean) then (string) else (string)
if <(boolean) = [true]> then
say [good]
else
say [WHAT!]
end
and wow that teached me how to make if then else in more blocks

This would be so much more useful if we had custom reporters…










If you can read this, my signature cubeupload has been eaten by an evil kumquat!




or you just used Inspect Element, you hacker

;
little_kitten
Scratcher
500+ posts

?-Operator [inline if-then-else]

So, I saw a YouTube video on how to hack scratch and get this block:
(if<>then[]else[]) 
which basically, if the Boolean input was true, the string would be used, if it was false, though, the second would be used. It could be used like
say (if<key [space v] pressed?> then [Key space is pressed!] else [Key space is not pressed!] )for (2) secs
Now I thought, Well, wouldn't it be easier to just have it, and not have to hack and get it? And that's true. It would be easier.

Last edited by Paddle2See (Nov. 12, 2015 12:57:30)


The above post was likely clear sass. 10 outta 10.
Unless it wasn't. Which happens from time to time. Sadly.

Powered by DjangoBB