How do I (or can I) reference objects/instances programmatically?

0 favourites
  • 3 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hi,

    Is it possible to reference an instance of an object by one of its variables?

    Say I have Text fields called text1, to text9, each with an instance variable of ID that I manually enter, and a number of other instance variables called segment1, segment2, segment3, ..., segment9

    I have a 'for' loop, and within the loop I want to be able to say:-

    iCtr = 0

    For 0 to 9

    Carry out a task to calculate result

    'Update text(n) field with result

    set text & (ictr).Segment1 = result

    'or even

    set text.Segment(ictr) = result

    iCtr = iCtr+1

    Next

    or failing that, could I do similar with a Global constants, e.g global1, global2, global3, ..., global9:-

    iCtr = 0

    For 0 to 9

    Carry out a task to calculate result

    'Update global with result

    set global & (ictr) = result

    iCtr = iCtr+1

    Next

    Basically I am trying reference fields/objects programmatically using their name/id. I know I could loop through object instances, but I already have a number of loops so I am trying to avoid that if at all possible.

    Thanks in advance!

  • Pick by Evaluate Object.yourinstancevariable=loopindex

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Pick by Evaluate Object.yourinstancevariable=loopindex

    Perfect - thank you!!!

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