Refer to different objects depending on circumstance

Just started using Construct 2? Post your questions here

Post » Sun Mar 30, 2014 1:55 am

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.
B
3
Posts: 3
Reputation: 181

Post » Sun Mar 30, 2014 5:03 am

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
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 3 guests