tower defense upgrade problem..

Get help using Construct 2

Post » Tue Jul 19, 2016 10:47 am

I have created a upgrade button for my tower defense game and sucessfully made upgradeble turrets to increase firepower. But i found something faulty, Once I upgraded the tower, ALL the other same turrets on the screen get upgraded. How do i fix this? I want only one turret to be upgraded.
B
6
Posts: 46
Reputation: 336

Post » Tue Jul 19, 2016 10:52 am

Is it a button/tower ?
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue Jul 19, 2016 10:58 am

tower. Once i upgrade one tower, all turrets of the same type get upgraded.
B
6
Posts: 46
Reputation: 336

Post » Tue Jul 19, 2016 11:04 am

How many buttons do you have ?
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue Jul 19, 2016 11:29 am

An option where (on mouse click rocket turret, spawn another object (the button) then, on button clicked, change animation frame to 1 (To change the appearence of the turret) )
B
6
Posts: 46
Reputation: 336

Post » Tue Jul 19, 2016 11:56 am

So each turret has one button.

Give both an instance variable 'id'. Give them the same value, as some kind of identification.
Turret 1 & his button gets an 'id' with value 1.
Turret 2 & his button gets an 'id' with value 2.

On button clicked, select the turret with the same id, do your stuff.

But it is much much easyer if you use containers. Bring turret & button in a container.
Then, on creating a turret it also creates a button.
From now on, if the button is selected, also right turret is selected.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue Jul 19, 2016 12:38 pm

can you send a capx file to demonstrate this? I have no idea what containers are or the code.
B
6
Posts: 46
Reputation: 336

Post » Tue Jul 19, 2016 12:49 pm

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Jul 20, 2016 2:08 pm

this made it even worse, now the turret instantly made a million copies of itself once placed down...
By the way, the turret is actually connected via a turretbase.
B
6
Posts: 46
Reputation: 336

Post » Wed Jul 20, 2016 3:27 pm

Generally speaking, when you click your button, you will need to "pick" your tower to be upgraded with conditions, so that your upgrade action only applies to the picked tower. There are many ways to pick, depending on how your project is set up.

A safe way is to pick by UID, which you can save to a variable as an action when you select a tower to begin with. I recommend storing this in an instance variable in the upgrade button. Let's call it SelectedTower.

On tower selected (on clicked/touched?) - Set instance variable Button.SelectedTower to Tower.UID

On upgrade button clicked,Pick tower by UID Button.SelectedTower - Do upgrade tower action
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests