Using variables from two instances at once

This forum is currently in read-only mode.
From the Asset Store
Change the size and position of everything without calculating anything!
  • 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.

  • 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')

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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')

    :O I never thought of using SOL this way! hmmmm

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)