Discuss Scratch

mica43683
Scratcher
500+ posts

Either/Or block

I think there should be an either/or block, that would act similar to the
(pick random (1) to (10))
block, but instead of choosing a random number, it chooses a random script.

It would look something like this:
either {
} or {
} :: control

You should be able to right-click it and get an option to extend it, giving more options to add scripts:
either {
} or {
} or {
} :: control

Now, what would this be used for? Good question! Here's an example:
when green flag clicked
forever
if <<touching [mouse pointer v] ?> and <mouse down?>> then
either {
say [Hehe!] for (2) secs
} or {
say [That tickles!] for (2) secs
} :: control
end
end

It would be an easy workaround from:
when green flag clicked
forever
if <<touching [mouse pointer v] ?> and <mouse down?>> then
set [variable v] to (pick random (1) to (2))
if <(variable) = [1]> then
say [Hehe!] for (2) secs
else
say [That tickles!] for (2) secs
end
end
end
It could be used in many different ways, and I think it could be a nice addition to Scratch.

Last edited by mica43683 (March 21, 2021 21:00:55)

ResExsention
New Scratcher
1000+ posts

Either/Or block

No support, why can't you just

if <(pick random (1) to (10)) = [1]> then
...
end
if <(pick random (1) to (10)) = [2]> then
...
end
if <(pick random (1) to (10)) = [3]> then
...
end
and so on:: grey ring

I don't see why a simple workaround like that could be disregarded, after all, it isn't that long.
mica43683
Scratcher
500+ posts

Either/Or block

ResExsention wrote:

No support, why can't you just

if <(pick random (1) to (10)) = [1]> then
...
end
if <(pick random (1) to (10)) = [2]> then
...
end
if <(pick random (1) to (10)) = [3]> then
...
end
and so on:: grey ring

I don't see why a simple workaround like that could be disregarded, after all, it isn't that long.
This wouldn't necessarily work. It would keep choosing from 1 to 10, and there's nothing stopping it from choosing multiple scripts at the same time.
ResExsention
New Scratcher
1000+ posts

Either/Or block

mica43683 wrote:

ResExsention wrote:

No support, why can't you just

if <(pick random (1) to (10)) = [1]> then
...
end
if <(pick random (1) to (10)) = [2]> then
...
end
if <(pick random (1) to (10)) = [3]> then
...
end
and so on:: grey ring

I don't see why a simple workaround like that could be disregarded, after all, it isn't that long.
This wouldn't necessarily work. It would keep choosing from 1 to 10, and there's nothing stopping it from choosing multiple scripts at the same time.

Hold on, you're right.

Here:

set [random_variable v] to (pick random (1) to (10))
if <(random_variable) = [1]> then
...
end
if <(random_variable) = [2]> then
...
end
if <(random_variable) = [3]> then
...
end
and so on:: grey ring

You can make the random_variable local so that it doesn't clutter up variable list when you're in other sprites. Also, this prevents them from interfering with each other if you use this more than once.

No support, workaroundable.

Last edited by ResExsention (June 14, 2019 08:14:28)

mica43683
Scratcher
500+ posts

Either/Or block

ResExsention wrote:

mica43683 wrote:

ResExsention wrote:

No support, why can't you just

if <(pick random (1) to (10)) = [1]> then
...
end
if <(pick random (1) to (10)) = [2]> then
...
end
if <(pick random (1) to (10)) = [3]> then
...
end
and so on:: grey ring

I don't see why a simple workaround like that could be disregarded, after all, it isn't that long.
This wouldn't necessarily work. It would keep choosing from 1 to 10, and there's nothing stopping it from choosing multiple scripts at the same time.

Hold on, you're right.

Here:

set [random_variable v] to (pick random (1) to (10))
if <(random_variable) = [1]> then
...
end
if <(random_variable) = [2]> then
...
end
if <(random_variable) = [3]> then
...
end
and so on:: grey ring

You can make the random_variable local so that it doesn't clutter up variable list when you're in other sprites. Also, this prevents them from interfering with each other if you use this more than once.

No support, workaroundable.
I put the workaround with the variable as an example of what you could use the either/or block as a workaround for. Also, the either/or block wouldn't clutter the variable list on any sprites.

Last edited by mica43683 (June 14, 2019 11:23:58)

Za-Chary
Scratcher
1000+ posts

Either/Or block

If you don't feel like messing with variables, you can also use custom blocks.

define random choice (number)
if <(number) = [1]> then

...

else
if <(number) = [2]> then

...

else
if <(number) = [3]> then

...

else
and so on
end
end
end



random choice (pick random (1) to (3)) // Then just run this block in your main code. Be sure to include all choices!
mica43683
Scratcher
500+ posts

Either/Or block

Za-Chary wrote:

If you don't feel like messing with variables, you can also use custom blocks.

define random choice (number)
if <(number) = [1]> then

...

else
if <(number) = [2]> then

...

else
if <(number) = [3]> then

...

else
and so on
end
end
end



random choice (pick random (1) to (3)) // Then just run this block in your main code. Be sure to include all choices!
My suggestion is a workaround from any other workaround. Just to make everything simpler.
ResExsention
New Scratcher
1000+ posts

Either/Or block

mica43683 wrote:

My suggestion is a workaround from any other workaround. Just to make everything simpler.

But aren't the workarounds simple enough?

Plus, I generally try to avoid nesting C blocks if I can avoid it, because there's no zebra striping so it's easy to lose track. This either/or block goes against all that. Maybe if zebra striping comes out along with this one I would probably use it.

I'm now voting conditional support.

Last edited by ResExsention (June 14, 2019 11:33:14)

mica43683
Scratcher
500+ posts

Either/Or block

ResExsention wrote:

mica43683 wrote:

My suggestion is a workaround from any other workaround. Just to make everything simpler.

But aren't the workarounds simple enough?

Plus, I generally try to avoid nesting C blocks if I can avoid it, because there's no zebra striping so it's easy to lose track. This either/or block goes against all that. Maybe if zebra striping comes out along with this one I would probably use it.

I'm now voting conditional support.
The point of it being extendable is so that you don't have to nest it.
SadNoob
Scratcher
27 posts

Either/Or block

No support. It doesn't have a lot of use cases and isn't very intuitive. Perhaps it would be more useful if it had probability options, but then it would be getting a little complicated.
WindOctahedron
Scratcher
1000+ posts

Either/Or block

SadNoob wrote:

Perhaps it would be more useful if it had probability options, but then it would be getting a little complicated.
Exactly. With the
set [variable v] to (pick random (1) to (8))
if <(variable) > [5]> then // prob. 1/2
...
else
if <(variable) > [7]> then // prob. 1/4
...
else

if <(variable) = [7]> then // both prob. 1/8
...

else // prob. 1/8
...
end
end
end
script, it is possible to make some things more probable than others.

Last edited by WindOctahedron (June 14, 2019 16:12:12)

mica43683
Scratcher
500+ posts

Either/Or block

WindOctahedron wrote:

SadNoob wrote:

Perhaps it would be more useful if it had probability options, but then it would be getting a little complicated.
Exactly. With the
set [variable v] to (pick random (1) to (8))
if <(variable) > [5]> then // prob. 1/2
...
else
if <(variable) > [7]> then // prob. 1/4
...
else

if <(variable) = [7]> then // both prob. 1/8
...

else // prob. 1/8
...
end
end
end
script, it is possible to make some things more probable than others.
Wouldn't
<(variable) > [7]>
also be greater than 5?
mica43683
Scratcher
500+ posts

Either/Or block

Bump
WindOctahedron
Scratcher
1000+ posts

Either/Or block

mica43683 wrote:

WindOctahedron wrote:

-snip-
Wouldn't
<(variable) > [7]>
also be greater than 5?
Oh, yes. I meant
set [variable v] to (pick random (1) to (8))
if <(variable) < [5]> then // prob. 1/2
...
else
if <(variable) < [7]> then // prob. 1/4
...
else

if <(variable) = [7]> then // both prob. 1/8
...

else // prob. 1/8
...
end
end
end
Thanks for pointing that out.

Last edited by WindOctahedron (June 15, 2019 09:22:24)

mica43683
Scratcher
500+ posts

Either/Or block

Bump
Truck11111
Scratcher
1000+ posts

Either/Or block

Support, although the workaround is easy, I do not want to use a custom block or variable just for one script.
mica43683
Scratcher
500+ posts

Either/Or block

Bump
mica43683
Scratcher
500+ posts

Either/Or block

Bump
mica43683
Scratcher
500+ posts

Either/Or block

Bump
mica43683
Scratcher
500+ posts

Either/Or block

Bump

Powered by DjangoBB