How do I select a specific instance of a spawned object

Get help using Construct 2

Post » Thu Jul 31, 2014 2:37 am

So I am making a tower defense game. I have an upgrade system that if you push a button the tower will upgrade but it is on every instance of the tower. How do I make it on a select instance of that tower rather than having the attributes be assigned to all of the towers at once?
B
4
S
1
Posts: 27
Reputation: 504

Post » Thu Jul 31, 2014 10:21 am

You need a condition to pick the specific tower that you want to upgrade. There are many ways to do it. You could store the UID of the tower in a variable when you click the tower. Then when you click the button, you pick the tower with the stored UID and upgrade it.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Thu Jul 31, 2014 10:55 pm

@ramones I have been trying to figure out the UID thing for a little bit, following the things in the forums but I am just not able to get it to work. Any way you can point me in the right direction?
B
4
S
1
Posts: 27
Reputation: 504

Post » Thu Jul 31, 2014 11:52 pm

I think "pick" is the word you're looking for.

search the forums/manual/tutorials for pick and UID and see if you can't find what you're looking for.

and if you can't, let me know, and I'll see what I can do!
B
86
S
43
G
71
Posts: 601
Reputation: 43,619

Post » Fri Aug 01, 2014 11:45 am

Couple of examples:
You do not have the required permissions to view the files attached to this post.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Fri Aug 01, 2014 1:18 pm

This is the solution I have in a game I made.
I have an instance variable on it called ID, and I have also a variable let's say "Variable1", when spawning an object I set object.ID to variable1, and add 1 to variable1.. This way all the spawned objects will have IDs like 1...2...3...etc, then you can use Pick by comparison object where object.id equals whatever id you want.
Also for a TD game, I would think you needed to click the tower to upgrade it, so maybe you can pick the instance by overlapping point using Mouse.X and Mouse.Y
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Fri Aug 01, 2014 2:42 pm

@caiorosisca, yes this should work as what you are doing is essentially adding another UID to the object. It's not necessary because the object already has a UID, but I have been known to do this (and other similar things) in the past because it seems simpler. (It's not all that much simpler in fact, I just like using my own code).

Ramones Suggestion is what I would suggest (preferably the pick by Boolean, as it accounts for selecting multiple objects at once and doesn't have a global variable associated with it.)
B
11
S
3
G
1
Posts: 98
Reputation: 1,062

Post » Mon Aug 04, 2014 4:38 am

@ramones thank you for the capx files. I used them and altered them slightly to make it work for the most part. I am still tweaking things right now to make it work more for the game I am making but you set me on the right track. And every one else, thank you for your inputs I am trying to use a little of what everyone else has suggested also.
B
4
S
1
Posts: 27
Reputation: 504

Post » Mon Aug 04, 2014 5:10 am

Robsta wrote:@caiorosisca, yes this should work as what you are doing is essentially adding another UID to the object. It's not necessary because the object already has a UID


They are different, because UID's are not guaranteed to be sequential. But it is the same as IID + 1.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596


Return to How do I....?

Who is online

Users browsing this forum: imothep85, KTML5 and 9 guests