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

  • AlchimiaStudiosAlchimiaStudios Posts: 1,067
    edited July 2018 Accepted Answer

    @joloco2009

    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.

    Follow us: Twitter - Website

Answers

  • joloco2009joloco2009 Member Posts: 5

    How do i declare a global variable?

  • joloco2009joloco2009 Member Posts: 5

    Oh never mind I think you make a variable in the game tab.

  • joloco2009joloco2009 Member Posts: 5

    change attribute game.enemy1_health to game.enemy1_health-random(1,5)

    I tried writing the - but it doesnt seem to work.

  • AlchimiaStudiosAlchimiaStudios Member, PRO Posts: 1,067

    Not sure I understand. I've attached a demo for you to have a look at.

    Follow us: Twitter - Website

  • joloco2009joloco2009 Member Posts: 5

    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.

Sign In or Register to comment.