Upgrade HP question

jonhuttojonhutto Member, PRO Posts: 72
I am working on a defense game that has actors with hit points. You can use coins to upgrade their hit points. Here is the problem I am having:

Lets say I have 5,000 coins.
To upgrade, level 1 Hp to Level 2 HP You need 500 coins
To upgrade, level 2 Hp to Level 3 HP You need 700 coins
To upgrade, level 3 Hp to Level 4 HP You need 1000 coins (and so on) (etc etc)

My problem is I can't figure out how to make the upgrade button only upgrade 1 level. I want it to go from level 1 to level 2 ONLY. When I click upgrade, It uses all my available coins (5000 for example) and upgrades me as far as I can get with those 5000 coins.... Like level 7 or 8 HP.

I just want it to go from 1 level at a time.

My code:
Level 1
When touch is pressed AND game.actorHP = 1 AND game.coins are greater than or equal to 500
Change attribute game.actorHP to game.actorHP +1
Change game.coins to game.coins -500.

Level 2
When touch is pressed AND game.actorHP = 2 AND game.coins are greater than or equal to 700
Change attribute game.actorHP to game.actorHP +1
Change game.coins to game.coins -700.

and so on for the rest to level 10.

How can I make it only upgrade 1 level at a time? Couldn't find any threads on this. Maybe I'm searching the wrong key words. Any help is greatly appreciated!

Comments

  • TokuharaTokuhara Member Posts: 94
    Did you tried to change the "When touch is pressed" to "When touch is released"?

    If you did try and it didn't work you can try this:

    Can create an integer attribute inside your button called WhatLevel with value 1 so you can track what level your HP is.

    -------------------
    LEVEL 1
    -------------------
    When touch is pressed AND game.actorHP = 1 AND game.coins are greater than or equal to 500 AND self.WhatLevel = 1
    Change attribute game.actorHP to game.actorHP +1
    Change game.coins to game.coins -500
    Timer - After 1 second Change self.Attribute to self.Attribute + 1

    -------------------
    LEVEL 2
    -------------------
    When touch is pressed AND game.actorHP = 1 AND game.coins are greater than or equal to 500 AND self.WhatLevel = 2
    Change attribute game.actorHP to game.actorHP +1
    Change game.coins to game.coins -500
    Timer - After 1 second Change self.Attribute to self.Attribute + 1
  • jonhuttojonhutto Member, PRO Posts: 72
    Thanks so much Tokuhara! It seems to be working.
Sign In or Register to comment.