Turn Based RPG "attack command" problem

Get help using Construct 2

Post » Tue Mar 24, 2015 5:48 am

Hello!

I'm trying to make a turn-based RPG like Dragon Quest and Wizardry but I'm struggling when trying to code attacks in enemies.

How I'm doing:

* Every "enemy" object has a health variable and they are grouped in a family ("enemies").

* I made a global variable named "selected" to track what enemy the player wants to attack.

* When the player click the "attack button", the instance within the "Enemies" family is picked and....that is when I don't know what to do! I wish I could make something like "substract selectUID.health".

I want to access the health variable of the UID selected but I don't know how.

Need I to make an attack for every object separately or there is a way to code a "standard attack" that works with every enemy in the game?

Image

Image
B
7
S
2
G
1
Posts: 13
Reputation: 1,101

Post » Tue Mar 24, 2015 7:26 am

Make Health a property of the Enemy family, so instead of having GuardHealth or GoblinHealth, you just have Enemy.Health.

Add another Family instance variable called "attackfunction". Let that variable contain the name of a function, like "EnemyAttackFunction". then you can make an attack function with that name, That lets you have one main attack function that everything in the family defaults to, but you can still use a different function for special cases.

If you are interested in learning more, read up on something called polymorphism, which is an important concept in programming, even in Construct 2. Also, as always, feel free to ask questions ^_^
B
14
S
5
G
1
Posts: 189
Reputation: 1,536

Post » Tue Mar 24, 2015 4:34 pm

Many thanks @bladedpenguin!

You really saved me. I tried everything I could think for weeks and nothing could solve my problem.

I didn't knew I could make a family variable and change the value in the object.

And the "attackfunction" variable works wonders!

Here is how it is now:

Image
B
7
S
2
G
1
Posts: 13
Reputation: 1,101


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests