I’ve often gotten unexpected results when trying to mix AND and OR in Ready Events. This example from the instructions for the Ionic Twist game seems to suggest that “When” rows are evaluated left to right. Is that correct?
In other words, the following event would be evaluated as ((A or B or C) and D), right?
@Ready, I’m afraid I wasn’t very clear in my question. I wasn’t asking if the event from the Ionic Twist game is composed correctly, but rather I was asking if I correctly understand that each row in the When clause is evaluated one at a time, top to bottom, with the cumulative result used as the left-side value at each step. (As opposed to, say, treating AND as multiplication and OR as addition, and applying the equivalent standard rules for evaluating numerical expressions.)
@kenobi, your reply confirms my own observations. This is both good to know and a little disappointing to learn that it really is like that
I had a funny glitch with a Tynker game once.
I coded to measure the distances 4 dots were away from the players sprite and have the sprite move towards the closest.
This was done in a set order instead of all distances measured at once.
This sometimes caused a glitch where the sprite couldn’t choose which dot to head towards because of equal distances and the sprite kept changing direction.
Having a list with OR could cause a similar problem in theory.
A list of OR where multiple items evaluate to true shouldn’t normally be ambiguous, however, because OR is commutative (the order doesn’t matter). For example (A OR B OR C) is true iff (B OR A OR C).
It’s the lacking ability to apply brackets that makes things challenging (plus lack of NOT), or even to know for certain where implied brackets are applied.
I wanted to tell you guys that this can work in different ways, if you want the “Or” condition to work differently for each of the objects in one event, you just need to add the object to the class, for example:
All objects in class Right/Position/Left of object/ Center
OR
All objects in class Left/Position/Right of object/ Center
OR
All objects in class Up/Position/Above of object/ Center
OR
All objects in class Down/Position/Belowe of object/ Center
DO
Affected object in class Right/Clone/Remove Clone
Affected object in class Left/Position/Left in over time/1 m/s
Affected object in class Up/Explosion Effect/LSet Active/yes
Affected object in class Down/Clone/Clone Object/New Object
In this case, each condition will be fulfilled separately for each of the objects.
If you are not using a class, then you cannot select an object separately … since you specify an action for all objects under different conditions. Hope this helps.
@Ready, thank you for this helpful tip! So in other words, in a When clause, each row referencing a class is really a selector which returns a subset of the class, and combining class selectors with OR gives multiple result sets that can be referenced in the Do clause by the class name.
Is it then possible to create set unions and set intersections via multiple rows referencing the same class along with the OR and AND operators, respectively? In other words:
Example 1:
All objects in class MyObjects/Position/Left of object/ LeftEdge
OR
All objects in class MyObjects/Position/Right of object/ RightEdge
DO
Affected object in class MyObjects/Angle/Face object/CenterObject
Affected object in class MyObjects/Forward over time/1 m/s
Would this select all MyObjects that are either on the left or right sides, and make them move towards CenterObject?
Example 1a:
All objects in class MyObjects/Position/Left of object/ LeftEdge
OR
All objects in class MyObjects/Position/Right of object/ RightEdge
AND
Variable/state/=/1
DO
Affected object in class MyObjects/Angle/Face object/CenterObject
Affected object in class MyObjects/Forward over time/1 m/s
Would this do the same as Example 1, but only if state==1?
Example 2:
All objects in class MyObjects/Position/Right of object/LeftEdge
AND
All objects in class MyObjects/Position/Left of object/RightEdge
DO
Affected object in class MyObjects/Angle/Rotate CW/30 degrees
Would this select all MyObjects that are in the center region i.e. between the side edges (and rotate them 30 degrees)?
Hi @auntiel! No problem!
For the “1” and “1a” examples this should work, for the “2” - i think more correct if you use the “Select Instance Object in Class” parameter:
Select Instance Object in Class MyObjects/Angle/Rotate CW/30 degrees
Thank you for the advice, @Ready! Can you help me understand the difference between “Affected object in class” and “Select Instance Object in class”? I’ve tried many times unsucessfully to discover the difference through experimentation, but it seems to give the same result either way.
Can you clarify for us the underlying principles of these two options? What exactly do they mean? In other words, what is the logic, or code structure, that each is translated to?
“Affected” - building logic for working with this action is somewhat similar to the work of ordinary objects. If one of the objects has the condition true, the action is applied to all objects in the class (Effect on all objects in the class)
“Select Instance” - Under several conditions for objects in one class, we iterate over the class to search for a specific object that meets all the criteria declared (Effect on one of the objects in the class)
It is worth noting that work on “Select Instance” is still ongoing and sometimes some of your events may not work fully.