How do I refer to an object with a variable

0 favourites
  • 4 posts
From the Asset Store
112 High-Quality destruction sounds for videogames
  • I have a number of objects, text and images, that I want to change the content of.

    At the moment the only way I can see to do that is to call individually code the change to each of these objects. It would be far more efficient if I could include them in a loop and just reference them using a array.

    for example the array could consist of text1, text,2 text3, text4 ( The name of the four text objects )

    then a loop could be used to cycle through the array and update each text object with the new data. Is there a way to do this in Construct? I have yet to find it.

    Any help would be most appreciated.


  • You can't refer objects in C2 by their string name.

    What you can do is add all these text1,text2... objects to a family TextsFamily, create an instance variable "code" on the family, and then you'll be able to pick any object (member of the family) by code.

    For example:

    TextsFamily compare instance variable code="text4" -> TextsFamily set Text to "abcd"

    Same approach with sprites.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Alternatively if you want to use an array, you can index the UID of each text object into the array.

  • Thanks for the help guys. Most appreciated.

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