Upgrade System (one by one)

0 favourites
  • 9 posts
From the Asset Store
Tank & Bang
$20 USD
80% off
Great amount of unique upgrade, a lot of enemy types. Upgrade your tank and destroy all enemies!
  • Hi, so right now I have:

    UpgradeAmount - Amount of times it's been successfully upgraded (when clicked, if had enough money then do this etc)

    Money - The balance

    UpButton - The upgrade button, when clicked it'll determine whether or not the player has enough money and will continue if so.

    And right now I have it setup like this

    ___________________________________________________

    On touched object "UpButton"__|___System | Set Upgrade to 1

    System | Upgrade = 0___________|___Subtract 30 from Money

    Money >= 30____________________|

    ___________________________________________________

    On touched object "UpButton"__|___System | Set Upgrade to 2

    System | Upgrade = 1___________|___Subtract 100 from Money

    Money >= 100____________________|

    ___________________________________________________

    I have it setup like this because I want the upgrades to go 1 by one, however right now if they have enough money for the next upgrade

    it buys as many upgrades as it can. How can I stop this?

  • It's because of Construct's top down structure so every event becomes true for one click if they have enough money. You can add a short wait of 0.1 seconds in, before you set the upgrade variable.

  • It's because of Construct's top down structure so every event becomes true for one click if they have enough money. You can add a short wait of 0.1 seconds in, before you set the upgrade variable.

    Thank you very much, helped a lot.

  • You could even wait just 0 seconds [quote:20tpyi4h]One more trick: "Wait 0 seconds" postpones the following actions until the end of the event sheet.

    This way you don't even need to really "Wait", because the action is executed in the same tick, but it's the last action that is executed. Anyway, you can look it up here.

  • You should NOT use Wait for this, just have On touch as the top event, then use sub-events to break down the extra conditions:

    On touched object "UpButton"

    System | Upgrade = 0

    Money >= 30____________________|___System | Set Upgrade to 1

    Else

    System | Upgrade = 1

    Money >= 100____________________|___System | Set Upgrade to 2

  • blackhornet, in your example you can only do 2 upgrades.

    TylerJS, I would do something like this:

    On touched object "UpButton"
      Local variable upgradeSuccessful=0
    
      System | Upgrade = 0 
      Money >= 30           Subtract 30 from Money
                                        Set upgradeSuccessful to 1
    
      System | Upgrade = 1 
      Money >= 100           Subtract 100 from Money 
                                        Set upgradeSuccessful to 1
    
      System | Upgrade = 2 
      Money >= 200           Subtract 200 from Money 
                                        Set upgradeSuccessful to 1
    
      if upgradeSuccessful=1  Add 1 to Upgrade 
      Else  <dispay a message that payer doesn't have enough money>
    [/code:3rx8syyf]
    
    Also, if you are making the game for touch screen, use On Tap event for buttons.
  • dop2000

    You can add subsequent Else conditions.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • blackhornet , forgot about that, yes you are right.

    Here is a shorter version if you're comfortable with using ternary operators:

    On Tap on object "UpButton"
      Local variable upgradeCost=0
      upgradeCost = (Upgrade=0 ? 30 : Upgrade=1 ? 100 : Upgrade=2 ? 200 : Upgrade=3 ? 500 : 0)
    
      if upgradeCost>0 and  Money>=upgradeCost
         Add 1 to Upgrade 
         Subtract upgradeCost from Money
     [/code:30h4ijhz]
  • Hey TylerJS!

    You should definitely consider storing your upgrade info on an array or string and have just ONE event for upgrading. It would save you a ton of work and is infinitely scalable.

    For instance (using string):

    upgradeCosts = "30,100,230,500"
    currentUpgrade = 0
    
    On Tap on object "UpButton"
    Money >= tokenAt(upgradeCosts, currentUpgrade, ",")
            Add 1 to currentUpgrade
            Subtract int(tokenAt(upgradeCosts, currentUpgrade, ",")) from Money
    [/code:1ve4qf1v]
    
    Hope that helps. Cheers!
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)