Using variables from two instances at once

For questions about using Classic.

Post » Sun Nov 01, 2009 1:42 am

Ok, so here's my situation. I have these "wave" objects, representing ocean waves. They have the private variables MomentumUp, MomentumDown, MomentumRight, and MomentumLeft. Amogn others, but those are the relevant ones.

I want to set it up so that if two of these waves collide (overlap, in this case; it's grid-based), they combine into one. I need to do things like add their MomentumDown variables together, or use their opposing momentums - left and right - to cancel each other out.

What I need, in pseudocode:

-WaveA and WaveB collide.
-Spawn CombinedWave.
-CombinedWave Momentum = WaveAMomentum+WaveBMomentum

The problem I'm running into is that, since all three of these objects - WaveA, WaveB, and CombinedWave - are instances of the same class, I have no idea how to differentiate between their variables within the same equation. I know how to do it normally through manipulation of the SOL, but in this case I'd need to differentiate between at least WaveA and WaveB within the same equation, and the techniques I understand are not possible.

I can think of a way around this, involving saving these PVs in proxy variables that I CAN distinguish between, but the end result would be extremely convoluted and messy, and I'm sure there is a better way. I've read all of the documentation I can find on this subject, and searched the forums, but no luck for solving a circumstance like this.

I would really appreciate any advice. Thanks in advance!

EDIT: And if I somehow missed nice documentation on this very subject, then definitely link me to it! I feel like this must be something that people have run into before, and I'm likely just missing existing resources explaining it.
B
1
G
3
Posts: 4
Reputation: 833

Post » Sun Nov 01, 2009 2:03 am

Try using subevents to calculate the sum:

+ On collide between Sprite and Sprite
---+ Always
---> Set global 'sum' to 0

---+ For each Sprite (should iterate only over picked sprites - the two colliding ones)
---+ Add Sprite('momentum') to global 'sum'

---+ Always
---> Create object, set momentum to global('sum')
Scirra Founder
B
359
S
214
G
72
Posts: 22,948
Reputation: 178,532

Post » Sun Nov 01, 2009 3:21 am

you could also have the wave part of a family then differentiate them by choosing either the family or the object itself. That way it's part of 2 sols
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Sun Nov 01, 2009 11:01 pm

[quote="Ashley":m7bxcgvo]Try using subevents to calculate the sum:

+ On collide between Sprite and Sprite
---+ Always
---> Set global 'sum' to 0

---+ For each Sprite (should iterate only over picked sprites - the two colliding ones)
---+ Add Sprite('momentum') to global 'sum'

---+ Always
---> Create object, set momentum to global('sum')[/quote:m7bxcgvo]
:O I never thought of using SOL this way! hmmmm
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests