How do I select a specific instance of a spawned object

0 favourites
  • 9 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • 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?

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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?

  • 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!

  • Couple of examples:

  • 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

  • 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.)

  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)