Refer to different objects depending on circumstance

0 favourites
  • 2 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • I have a bit of a problem. I'm making a turn-based RPG where the player and enemy repeatedly attack each other. Whenever I update the code for attacking, I have to copy-paste it from the player to the enemy, replacing "player" with "enemy" and vice-versa. This becomes tedious, so I decided to create global variables called "attacker" and "attacked," which would be set depending on who's attacking who. In the code, I could refer to them instead of having two chunks of..."code."

    The problem is that Construct 2 won't let me enter variable names as objects. Can this be done, do I have to keep copy-pasting, or is there another way to solve this problem?

    Random, unrelated question that I DEFINITELY bothered to research EXTENSIVELY before asking: Is there a way to enter Java code or something similar instead of selecting actions? I can code much more quickly than I can click on things.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Functions should be used for actions you don't want to repeat. You can pass the object's UID to the function using parameters and then pick the object based on the UID number. Put the player and enemy on the same family so you can apply the function to any object inside the family

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