Turn Based RPG "attack command" problem

0 favourites
  • 3 posts
From the Asset Store
A well commented RPG game template to learn from or use as a base for your own game!
  • 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?

  • 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 ^_^

  • Try Construct 3

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

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

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