How to "construct" an object name using variables

Get help using Construct 2

Post » Wed Aug 26, 2015 10:25 am

jabelone wrote:[....] I want to be able to do something to an object called "item&userSelection" (item75). For example, spawn object at "item&userSelection&.X" (item75.X) if the user enters 75. [...]


Ok. So your problem is that you want to pick an object by name which can be "randomly" generated. Here we have bad and good news. The bad news is that you cannot pick an object by name in Construct2. The good news is there is a comfortable workaround. @Kyatric already explained that a bit, but lets do it in details.

First think of C2 object more like of a class in programming. It's not really an instance. The one you have on your layout is an instance already and has some unique ID. But you want to call it by name - no problem. All you have to do is to name it first.

So go to your object settings and add a variable "instanceName" which should be a text type. Now you can name any instance (new on the fly, or name the one on layout manually). Once you have it named you are ready to pick it using "System -> Pick by comparsion" function. This function requires two parameters which will be compared. So as a first parameter you should type yourObjectName.instanceName and as a second one "item"&userSelection.

And here you go, you just picked an instance you needed and you can do whatever you want to do with it.
ImageImageImage
B
31
S
19
G
82
Posts: 1,039
Reputation: 46,207

Post » Thu Aug 27, 2015 3:32 am

Thanks @Kyatric that is almost what I want to do but flipped. I have one single object that needs to navigate to many different ones based on user input. (the different objects are all done in the layout editor before runtime)

Thank-you so much @BackendFreak that is almost exactly what I wanted to do. I have a layout with almost 200 objects spread out over it. A single object needs to path find to whichever numbered object the user specifies. I never thought of using an instance variable like that before but it makes so much sense.

Thank-you so much to everyone who has helped! :D
B
7
Posts: 27
Reputation: 407

Post » Thu Aug 27, 2015 9:59 am

Glad I could help. Don't forget to show us this game when you're done! ;)
ImageImageImage
B
31
S
19
G
82
Posts: 1,039
Reputation: 46,207

Post » Thu Aug 27, 2015 8:25 pm

I sure will! You know those interactive displays in the shopping centres that tell you how to get to a shop? I'm making one of them for my work but for staff and in the form of a mobile app. I deliver pizza's for Dominos and there are some very large "townhouse" (that's what us Aussies call them) complexes that are difficult to navigate as they are all classed as units with the one street address. So I'm making an app with them all in it so it makes it easier for drivers to get to the customer's door quicker. It also shows the best parking and any tips like how to use the buzzers etc.

It's still in what I would call alpha at the moment so it's missing lots of things and sometime's I'll accidently break something. You can actually see the latest version here (best on phones): https://jabelone.com.au/dh When it's done I'll post it's link on google play here. My teacher wants me to do another one for the school he likes it that much. ;)
B
7
Posts: 27
Reputation: 407

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests