Variable contains a sprite name

0 favourites
  • 2 posts
From the Asset Store
Color Variable
$4.50 USD
10% off
Easily store, modify, read and manipulate colors with Color Variables!
  • 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!

  • Try Construct 3

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

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

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