Discuss Scratch
- mica43683
-
500+ posts
Either/Or block
I think there should be an either/or block, that would act similar to the
It would look something like this:
You should be able to right-click it and get an option to extend it, giving more options to add scripts:
Now, what would this be used for? Good question! Here's an example:
It would be an easy workaround from:
(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 clickedIt could be used in many different ways, and I think it could be a nice addition to Scratch.
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
Last edited by mica43683 (March 21, 2021 21:00:55)
- ResExsention
-
1000+ posts
Either/Or block
No support, why can't you just
I don't see why a simple workaround like that could be disregarded, after all, it isn't that long.
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
-
500+ posts
Either/Or block
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. No support, why can't you justif <(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.
- ResExsention
-
1000+ posts
Either/Or block
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. No support, why can't you justif <(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.
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
-
500+ posts
Either/Or block
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.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. No support, why can't you justif <(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.
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 mica43683 (June 14, 2019 11:23:58)
- Za-Chary
-
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
-
500+ posts
Either/Or block
My suggestion is a workaround from any other workaround. Just to make everything simpler. 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!
- ResExsention
-
1000+ posts
Either/Or block
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
-
500+ posts
Either/Or block
The point of it being extendable is so that you don't have to nest it.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.
- SadNoob
-
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
-
1000+ posts
Either/Or block
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))script, it is possible to make some things more probable than others.
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
Last edited by WindOctahedron (June 14, 2019 16:12:12)
- mica43683
-
500+ posts
Either/Or block
Wouldn'tPerhaps it would be more useful if it had probability options, but then it would be getting a little complicated.Exactly. With theset [variable v] to (pick random (1) to (8))script, it is possible to make some things more probable than others.
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
<(variable) > [7]>also be greater than 5?
- WindOctahedron
-
1000+ posts
Either/Or block
Oh, yes. I meantWouldn't -snip-<(variable) > [7]>also be greater than 5?
set [variable v] to (pick random (1) to (8))Thanks for pointing that out.
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
Last edited by WindOctahedron (June 15, 2019 09:22:24)
- Truck11111
-
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.