How do I access different objects in a loop?

Get help using Construct 2

Post » Tue May 31, 2016 7:14 pm

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
B
12
S
3
Posts: 211
Reputation: 1,477

Post » Wed Jun 01, 2016 7:32 am

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
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Jun 01, 2016 10:36 am

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.
B
12
S
3
Posts: 211
Reputation: 1,477


Return to How do I....?

Who is online

Users browsing this forum: dand, mageekm, oosyrag, Yahoo [Bot] and 32 guests