Upgrade System (one by one)

Get help using Construct 2

Post » Sat Sep 09, 2017 5:20 pm

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?
B
5
S
2
Posts: 5
Reputation: 435

Post » Sat Sep 09, 2017 6:44 pm

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.
B
53
S
21
G
95
Posts: 2,453
Reputation: 56,121

Post » Sat Sep 09, 2017 7:08 pm

plinkie wrote: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.
B
5
S
2
Posts: 5
Reputation: 435

Post » Sat Sep 09, 2017 7:11 pm

You could even wait just 0 seconds
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.
B
21
S
7
G
1
Posts: 168
Reputation: 1,925

Post » Sat Sep 09, 2017 7:25 pm

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
ImageImageImage
B
72
S
22
G
290
Posts: 3,886
Reputation: 159,513

Post » Sun Sep 10, 2017 5:21 am

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

@TylerJS, I would do something like this:
Code: Select all
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>


Also, if you are making the game for touch screen, use On Tap event for buttons.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
19
S
9
G
158
Posts: 2,401
Reputation: 84,429

Post » Sun Sep 10, 2017 6:29 am

@dop2000
You can add subsequent Else conditions.
ImageImageImage
B
72
S
22
G
290
Posts: 3,886
Reputation: 159,513

Post » Sun Sep 10, 2017 6:52 am

@blackhornet , forgot about that, yes you are right.

Here is a shorter version if you're comfortable with using ternary operators:
Code: Select all
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
 
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
19
S
9
G
158
Posts: 2,401
Reputation: 84,429

Post » Sun Sep 10, 2017 3:24 pm

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):
Code: Select all
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


Hope that helps. Cheers!
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
22
S
6
G
3
Posts: 722
Reputation: 4,026


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests