Discuss Scratch

videobob
Scratcher
100+ posts

___ or ___ but not both block

A new block in the operations section, this block works like the or block, but if both commands are activated, the block will not work. So, let's say <Variable1=1> or <Variable2=2> but both. This means if one of them is correct, the script will run. If both are, the script won't. I hope you consider this!
Firedrake969
Scratcher
1000+ posts

___ or ___ but not both block

so XOR?

Workaround in pseudocode:

if (x or y) and not (x and y)
davidkt
Scratcher
1000+ posts

___ or ___ but not both block

Yeah, but call it xor, and have something explaining what it does.
<<> xor <>::operators>

Last edited by davidkt (March 24, 2014 20:29:20)

AonymousProfessor
Scratcher
100+ posts

___ or ___ but not both block

Workaround: (by xlk)
<not <<bool1 :: grey> = <bool2 :: grey>>> //Yes, booleans can go into an equals block
EmeraldDaffodils
Scratcher
100+ posts

___ or ___ but not both block

If you mean when both variable are activated, then:

when green flag clicked
forever
if <(spuds) = [10]> then

change [or] by [1]
end
if <(corks) = [15]> then

change [spuds] by (1)
end
end
wait until <(or) = [2]>
say [Congrats! You completed the challenge!]

Last edited by EmeraldDaffodils (March 23, 2014 21:02:31)

videobob
Scratcher
100+ posts

___ or ___ but not both block

EmeraldDaffoldis, that's the exact opposite of what I mean, and there is a better way of doing that using the and block. I mean if only one of them is true, but not both.
Greatguy123
Scratcher
500+ posts

___ or ___ but not both block

when green flag clicked
forever
if <<<key [left arrow v] pressed?> or <key [right v] pressed?>> and <not <<key [left arrow v] pressed?> and <key [right arrow v] pressed?>>>> then

if <key [left arrow v] pressed?> then

change x by (3)
end
if <key [right arrow v] pressed?> then

change x by (-3)
end
end
end
This is a very impractical script, but you get the idea. I realize it's a lot more complicated, though, so I think it would be a good idea to add XOR, and perhaps some other ones as well.
ExtremeLogic
Scratcher
500+ posts

___ or ___ but not both block

videobob wrote:

A new block in the operations section, this block works like the or block, but if both commands are activated, the block will not work. So, let's say <Variable1=1> or <Variable2=2> but both. This means if one of them is correct, the script will run. If both are, the script won't. I hope you consider this!
I don't know if this would work, but maybe it would?
when green flag clicked
if <<<(variable1) = [1]> or <(variable2) = [2]>> and <not <<(variable1) = [1]> and <(variable2) = [2]>>>> then
Some Block
end
I hope that's what you're looking for or that it helps.
Greatguy123
Scratcher
500+ posts

___ or ___ but not both block

ExtremeLogic wrote:

I don't know if this would work, but maybe it would?
when green flag clicked
if <<<(variable1) = [1]> or <(variable2) = [2]>> and <not <<(variable1) = [1]> and <(variable2) = [2]>>>> then
Some Block
end
I hope that's what you're looking for or that it helps.
That's basically what I did, except it's better as an example.
DadOfMrLog
Scratcher
1000+ posts

___ or ___ but not both block

To repeat what AonymousProfessor said, and to apply it to the examples given above…

First, the example from ExtremeLogic:
when green flag clicked
if < not <<(variable1) = [1]> = <(variable2) = [2]> > > then
Some Block
end
Then your own example:
when green flag clicked
forever
if < not < < key [left arrow v] pressed? > = < key [right v] pressed? > > > then

if <key [left arrow v] pressed?> then

change x by (3)
end
if <key [right arrow v] pressed?> then

change x by (-3)
end
end
end

Using “not (a=b)” is far more concise than using “(a or b) and (not (a and b))” - since Scratch lets you drop in booleans for a and b.

Last edited by DadOfMrLog (March 25, 2014 19:58:25)

videobob
Scratcher
100+ posts

___ or ___ but not both block

DadOfMrLog: I didn't make that example. GreatGuy123 did.
braxbroscratcher
Scratcher
1000+ posts

___ or ___ but not both block

videobob wrote:

A new block in the operations section, this block works like the or block, but if both commands are activated, the block will not work. So, let's say <Variable1=1> or <Variable2=2> but both. This means if one of them is correct, the script will run. If both are, the script won't. I hope you consider this!

Easy workaround IN SCRATCHBLOCKS!

Just for all to see.
if <<<X> or <Y>> and <not <<X> and <Y>>>> then
blah blah blah script stuff.
end

So no support.

I did not mean any disrespect.

Last edited by braxbroscratcher (March 26, 2014 11:00:07)

Blueinkproductions
Scratcher
1000+ posts

___ or ___ but not both block

Support. The workaround is annoying.
DadOfMrLog
Scratcher
1000+ posts

___ or ___ but not both block

videobob wrote:

DadOfMrLog: I didn't make that example. GreatGuy123 did.
Oops, quite right!

@braxbroscratcher: the workaround you suggest has been mentioned above, but can get somewhat clumsy and long (as Greatguy123's example shows), which is the reason for the request for a “xor” operator.

However, there is a more succint workaround - for your example it would be:
if < not < <X> = <Y> > > then // where X & Y are boolean expressions - why I've left them red, rather than variable orange
blah blah blah script stuff.
end
It's really only one “not” operator more than a built-in “xor” would be, so I don't think a xor operator is needed.

To spell it out again:
< <X> xor <Y> > // category=operators X & Y are boolean expressions
is exactly the same as:
< not < <X> = <Y> > > // X & Y are boolean expressions
See my post above for more examples.

Last edited by DadOfMrLog (March 26, 2014 12:31:50)

CGRises
Scratcher
500+ posts

___ or ___ but not both block

braxbroscratcher wrote:

videobob wrote:

A new block in the operations section, this block works like the or block, but if both commands are activated, the block will not work. So, let's say <Variable1=1> or <Variable2=2> but both. This means if one of them is correct, the script will run. If both are, the script won't. I hope you consider this!

Easy workaround IN SCRATCHBLOCKS!

Just for all to see.
if <<<X> or <Y>> and <not <<X> and <Y>>>> then
blah blah blah script stuff.
end

So no support.

I did not mean any disrespect.
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

___ or ___ but not both block

Because I made a duplicate of this topic and it got closed, I will support this suggestion.
Hamish752
Scratcher
1000+ posts

___ or ___ but not both block

Support.
Cream_E_Cookie
Scratcher
1000+ posts

___ or ___ but not both block

Semi-support, worklaroundable:
<<<1> or <2 >> and <<not <<1> = <2>>> >

Last edited by Cream_E_Cookie (Aug. 1, 2015 23:08:58)

monstermash3
Scratcher
1000+ posts

___ or ___ but not both block

No support, just use the workaround.
<<<(variable) = [1]> or <(variable) = [2]>> and <not <<(variable) = [1]> and <(variable) = [2]>>>

Last edited by monstermash3 (Aug. 1, 2015 23:15:41)

Znapi
Scratcher
500+ posts

___ or ___ but not both block

If you want a shorter(and likely faster) workaround that what most people here are posting, do what @TheLogFather posted:
<not <[] = []>>

DadOfMrLog wrote:

…there is a more succint workaround - for your example it would be:
if < not < <X> = <Y> > > then // where X & Y are boolean expressions - why I've left them red, rather than variable orange
blah blah blah script stuff.
end
It's really only one “not” operator more than a built-in “xor” would be, so I don't think a xor operator is needed.

To spell it out again:
< <X> xor <Y> > // category=operators X & Y are boolean expressions
is exactly the same as:
< not < <X> = <Y> > > // X & Y are boolean expressions
See my post above for more examples.
You don't need the extra stuff in the other workarounds.

Powered by DjangoBB