Hi, I'm new. How do you reduce an enemys hp by clicking on an attack button?
Hi, I'm new. I'm making a turn based game and I made an attack button. I also made an attribute in the enemy actor called enemy1_health and it's 100. I want to to press the attack button and then the enemies health will go down by a random range of 1-5.
Best Answer
-
AlchimiaStudios Posts: 1,069
You can do it, but an attribute declared in a actor has a "local" scope.
This means you can only access that attribute from the actor itself, and not from the attack button actor.
If you declare a "global" or "game" attribute it can be manipulated across all actors.
Or a third option is a "scene" attribute which can only be manipulated per scene, but by all actors who are unlocked on the scene.
with a global attribute you would just write it as follows:
When touch is pressed:
do:
change attribute game.enemy1_health to game.enemy1_health-random(1,5)
if you want to see it happening add a display text and put game.enemy1_health into the expression.
Answers
How do i declare a global variable?
Oh never mind I think you make a variable in the game tab.
I tried writing the - but it doesnt seem to work.
Not sure I understand. I've attached a demo for you to have a look at.
Follow us: Twitter - Website
It doesn't seem to work. I typed game.enemy1_HP-Random(5,10) and then I will display game.enemy1_HP in the enemy actor.