Variable contains a sprite name

Discussion and feedback on Construct 2

Post » Mon Nov 28, 2011 11:29 pm

Hey,

I have a global text variable (WhereAmI) that stores the name of a sprite. I want to be able to use this variable to refer to this sprite's instance variables. I can't figure out how this would work.

For example, at the beginning of the game, WhereAmI is set to "Location1". The sprite Location1 has an instance variable of clue. I want to set a text object to contain the text from Location1.clue. Instead of referring directly to Location1, I want to use WhereAmI since I may want to pull clue from Location2 in another context. I can't use WhereAmI.clue, because the global variable WhereAmI has no instance variable clue.

I thought about using an if statement, but it doesn't look like those are implemented? That's a suboptimal solution anyway, I think.

In the end, I should probably store all this in an array or something and end up having to refer to Array[WhereAmI] or something. However, even if I do change the way I structure this particular action, using a variable to refer to a sprite seems like it could be useful.

Thanks for your help!
B
2
G
1
Posts: 2
Reputation: 604

Post » Tue Nov 29, 2011 12:03 pm

Have you checked the how do I FAQ to the section "Picking/selecting instance(s)" ?

Selecting/Picking the correct UID - LINK
Picking separate instances from a same object - LINK

This is not exactly what you want, since it doesn't rely on the name of the object, but picking through UID is pretty much the designed way to do picking in C2. You really should take a look in this direction.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,805


Return to Construct 2 General

Who is online

Users browsing this forum: Yahoo [Bot] and 15 guests