How do I access different objects in a loop?

0 favourites
  • 3 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • Hello,

    i would like to fill a 2d-array with values from different objects as shown in the picture:

    http://prntscr.com/baq5k3

    I have 3 objects named "object_1", "object_2", "object_3". Each of them has a different instance variables which i would like to store in an array. I could do it 1 by 1 but what if there are 1000 of these objects? it must be possible with a loop, right?

    Why is there nothing like GetObject(UID)..that would help alot...

    thank you

  • The link does not work.

    Question: is it realy needed to have differend objects ? You can not do it with instances of the same object ?

    If you need differend objects, then you best have accces to familys. Looping trough families is the same as looping truough instances ...

    Condition:

    Pick a group of objects.

    Pick the array

    Action

    Array > set size > width = object.count - 1, Height = amount of variables you need to store

    Z must be at least 1 .. Zero will make an unusable array

    Condition:

    System > For > name = "index", start = 0, end = object.count - 1 (because it is zero based)

    Now the loopcounter is the expression loopindex("index"), we use that as IID of an object and as X index in the array.

    You need Y indexes for the variables.

    So

    Sub condition

    System > Pick nth instance > object = object, instance = loopindex("index")

    Actions

    Array > set at XY > X = loopindex("index") , Y =0, value = Object.instancevariable1

    Array > set at XY > X = loopindex("index") , Y =1, value = Object.instancevariable2

    Array > set at XY > X = loopindex("index") , Y =2, value = Object.X

    Array > set at XY > X = loopindex("index") , Y =3, value = Object.UID

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The link works for me. Werid. But i completely forgot about families. This might have worked, but I already fixed the problem by just using 1 object with different animations.

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