Swap 2 objects in a larger code-chain?

0 favourites
  • 3 posts
From the Asset Store
Full game Construct 2 capx code source to post on Google Play
  • Hello,

    I work on a 2 player game and when I have a character finished for Player 1, I have to copy/paste the string of that Character and just replace the objects (P1model with P2model, P1bullets with P2bullets etc)

    But I can't replace a thing, when both, the Player 1 and Player 2 objects are inside the string.

    E.g. When hit player 2, reduce P1Stats.Damage from P2Stats.Health. (P1Stats is just an invisible object to safe information like damage, speed, health etc. so I can change it easily later)

    Now when I replace P1Stats with P2Stats, there will be obviously only P2Stats left inside the string so I cannot just replace the missing P2Stats.

    I kind of "solved" it by making an placeholderStats object so I can replace them first with it, and then with the actual object but isn't there an easier solution?

  • That looks like a decent solution. That's what they thought us in basic programming for singular strings or quantities.

    However it sounds like your ideal place holder would be a 2-dimensional array given that there are many quantities for player 1 and 2 (I'm guessing life, mana, spd...)

    Array[0][x][x] can hold values for Player 1

    Array[1][x][x] can hold values for Player 2 or something like that.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • MPPlantOfficial

    Thank you for your answer! I am going to inform me a bit more about arrays ^^

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