Guess this story is a never ending story. Yup i have to add something to this topic.
The follow .cap i stole from this topic. (i always misspell threat, so allow me to use 'topic' in stead ) viewtopic.php?f=3&t=1124&st=0&sk=t&sd=a&hilit=crap#p8059
You can download it from there, or pick it from this link. download/file.php?id=108
Fire it up, and take a look at it.
I am only interested in the event numbers 2, 3 and 4.
Back then i saw the error in this. But i had no 'general' solution. With 'general' pointing to something that will work in all situations. I do now.
Lets first analyze the problem.
There are 3 objects in this project. Sprite, Sprite2 and Sprite3. Personal i do not like unnamed objects. But anywayz.
All 3 objects are member of the group 'blue".
So in events 2 .. 4. You see an attempt to set the gravity in the platform behavior for a certain object to zero, when the vectorY in its platform behavior is also zero.
This looks ok j0h! Whats your problem now again !???
Um, well, the syntax is right. And it does exactly what it is programmed to do.
Namely, when the object sprite's VectorY = zero, it will set the gravity in ALL objects that are member of the family Blue to zero.
And it does this in event 2 and 3 and 4, resulting in .. well i guess you can see that.
Do not laughs ! I have done those kinda things myself. I am dead serious ! ( lol well ).
Now lets upgrade this isolated little error to something 'general' to learn from.
The condition in event number 2 is a (what i call) Flow Condition. It runs its Sub Events and Actions when the condition is true.
But what we need here is a Pick Condition. In this case we need to take all the Blue objects, filter out those who's VectorY is not zero, and feed the left overs to the Sub Events and Actions.
Yep, its a Picking Objects situation, why its on its place in this topic.
We do have a small problem here though. The expression as used in the events in this .cap, can not be accessed using a Family.
Thats is not a bug or so, thats rather a very normal thing. Imagine an object having 2 platform behaviors. And at same time being member of a family with 10 other objects, who have only 1 platform behavior attached. Now when accessing the expressions trough the family name, witch VectorY shall the system take ? The one of the first behavior or the one of the second behavior ?
We need a good Pick Condition to make this work.
So lets convert *Flow* to *Pick*.
Let me show you in steps "how to".
Make a private variable in the objects.
Use the "for each object" system loop to walk trough the objects and set the private variable to the Expression. (in this case that would be to the VectorY in the platform behavior)
It does not matter in what order the "for each" walks trough the objects, so do not worry about that.
Now you can use the Pick Condition "Compare Private variable" to pick objects based on the stored expression.
Problem solved ! : )
You can see this work in this .cap download/file.php?id=107
Hope this was a help.