How do I use multiple individually selectable objects?

Just started using Construct 2? Post your questions here

Post » Fri Jul 08, 2016 11:31 pm

I’m working on a management game, and there are going to be, on a map, 60 or 70 different purchasable buildings. Each one will have different information. I don’t want to make each one a separate sprite, and am using instance variables. I want to be able to click on each building from the map, and have a bar on the side that shows whether or not it’s been purchased or not, as well as its name and other information about it. Is there a way to link objects to local variables? Each of my buildings has a name, as a local variable, and I want it displayed on the side of the screen when I click on the building. Is there a way I can automatically have it set the text on the side of my screen to match the local variable of each building when I click on it, like I might with a global variable? I know I could have a separate event for every single building set the text as the name of that building when I click on it, but that seems like an unnecessary hassle. I’ve run into another problem. As I said before, I want each building to be individually purchasable, but how do I tell Construct what building is selected. I thought that I would just add a “selected” local variable to the buildings that would be 0 by default, and would be set to 1 if it was clicked on, and to zero again after you clicked on another building (and then that other building would be 1) so it would only let you purchase the building when the value was 1, and then it would know which building to change the “purchased” local variable of. The problem is, I can’t figure out how to trigger an event to set the “selected” variable back to zero. If I click on a couple of buildings, and then the purchase button, it will purchase all of them. How do I keep just one building selected at one?

Thanks,

nhagan19
B
4
S
1
Posts: 3
Reputation: 306

Post » Sat Jul 09, 2016 3:18 am

I meant instance variables. Replace all of the times I referred to local variables with instance variables.
B
4
S
1
Posts: 3
Reputation: 306

Post » Sat Jul 09, 2016 3:47 am

When you click on the building it should be the only picked building, so just set your text object to building.Name, or whatever your instance variable is. An alternative for the Selected instance variable is a Global that is set to the UID of the currently selected building. Then whenever you need to do something with that building, you can pick it by UID, with that global. Using an instance variable can be done, but you need a Pick all buildings first, so you can set the value to 0, then when you pop back to the top level you set the selected value to 1.
It would be easier if you posted a CAPX. It will save time for any further questions.
ImageImageImage
B
71
S
22
G
240
Posts: 3,734
Reputation: 133,994

Post » Sat Jul 09, 2016 5:53 am

How might I provide you with a CAPX? And, while I'm replying, how might I set a Global to the UID of a currently selected building, and what do you mean by selected?

Thanks
B
4
S
1
Posts: 3
Reputation: 306

Post » Sat Jul 09, 2016 4:25 pm

Use a service like dropbox.com, to upload a CAPX file (Save as Single File...).
You said you click on a building, so you should have something like "On touched object X", so X is selected at that point, and you can save it's UID to a global: gvar = X.UID
ImageImageImage
B
71
S
22
G
240
Posts: 3,734
Reputation: 133,994


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests