Discuss Scratch
- videobob
-
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
-
1000+ posts
___ or ___ but not both block
so XOR?
Workaround in pseudocode:
if (x or y) and not (x and y)
Workaround in pseudocode:
if (x or y) and not (x and y)
- davidkt
-
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
-
100+ posts
___ or ___ but not both block
Workaround: (by xlk)
<not <<bool1 :: grey> = <bool2 :: grey>>> //Yes, booleans can go into an equals block
- EmeraldDaffodils
-
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
-
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
-
500+ posts
___ or ___ but not both block
when green flag clickedThis 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.
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
- ExtremeLogic
-
500+ posts
___ or ___ but not both block
I don't know if this would work, but maybe it would? 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!
when green flag clickedI hope that's what you're looking for or that it helps.
if <<<(variable1) = [1]> or <(variable2) = [2]>> and <not <<(variable1) = [1]> and <(variable2) = [2]>>>> then
Some Block
end
- Greatguy123
-
500+ posts
___ or ___ but not both block
That's basically what I did, except it's better as an example. I don't know if this would work, but maybe it would?when green flag clickedI hope that's what you're looking for or that it helps.
if <<<(variable1) = [1]> or <(variable2) = [2]>> and <not <<(variable1) = [1]> and <(variable2) = [2]>>>> then
Some Block
end

- DadOfMrLog
-
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:
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.
First, the example from ExtremeLogic:
when green flag clickedThen your own example:
if < not <<(variable1) = [1]> = <(variable2) = [2]> > > then
Some Block
end
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
-
100+ posts
___ or ___ but not both block
DadOfMrLog: I didn't make that example. GreatGuy123 did.
- braxbroscratcher
-
1000+ 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!
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
-
1000+ posts
___ or ___ but not both block
Support. The workaround is annoying.
- DadOfMrLog
-
1000+ posts
___ or ___ but not both block
Oops, quite right! DadOfMrLog: I didn't make that example. GreatGuy123 did.
@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 orangeIt's really only one “not” operator more than a built-in “xor” would be, so I don't think a xor operator is needed.
blah blah blah script stuff.
end
To spell it out again:
< <X> xor <Y> > // category=operators X & Y are boolean expressionsis exactly the same as:
< not < <X> = <Y> > > // X & Y are boolean expressionsSee my post above for more examples.
Last edited by DadOfMrLog (March 26, 2014 12:31:50)
- CGRises
-
500+ 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!
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
-
1000+ posts
___ or ___ but not both block
Because I made a duplicate of this topic and it got closed, I will support this suggestion.
- Cream_E_Cookie
-
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
-
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
-
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 <[] = []>>
You don't need the extra stuff in the other workarounds. …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 orangeIt's really only one “not” operator more than a built-in “xor” would be, so I don't think a xor operator is needed.
blah blah blah script stuff.
end
To spell it out again:< <X> xor <Y> > // category=operators X & Y are boolean expressionsis exactly the same as:< not < <X> = <Y> > > // X & Y are boolean expressionsSee my post above for more examples.