How do I iterate through children of an object's structure variable

Is it possible to use the “For every child in …” on an object structure variable? If so, what’s the syntax?

The Variable extension doesn’t appear to work on object variables.

I thought about doing it by converting it using ObjectVarToJSON, and then convert that to a scene variable and iterating through that. But is there a simpler way?

if your structure is an object array, you can use repeat Object.VariableChildCount() times
with a counter variable.
since the array variables are autosorted, there should be no issue using a counter from 0 to VariableChildCount()

Nice! That’s a neater and simpler way of doing it. Cheers :smiley:

I should have read your response more closely. It’s fine for arrays, but I’m using structures.

How is your structure composed?
Can you manually keep track of what values are added/removed?

If not, consider rework it to arrays, otherwise resorting a structure is a pain if you can’t use scene objects to rewrite it.

E:
you can read this:

to see why using an array is is probably the better solution

My structure is for a Point and Click game. It’s used to replace an object in another scene. For example, the case where a door is opened to a building in the current scene. In another scene, with the building visible, I want the door to opened too.

For example, the first scene is at the base of a hill, and there is a house at the top with the door closed (this door is not clickable). Click on the house and it opens the next scene which is set on top of the hill outside the house. In this scene, the door is also closed. Click on the door and it opens. Then when you move back to the base of the hill scene, the house at the top should now have it’s door open.

To achieve this, I keep track of which other scene objects will need to be changed. The structure holds the scene (or location) as the parent node, and the list of old object - new object pairs. In the previous example the old object is the house on the hill with door closed, while the new object is the house on the hill with door open.

So the clickable door object has the structure:
parent : BaseOfHillScene
child name: houseWithDoorClosedSprite, child value : houseWithDoorOpenSprite.

These details are stored in a global variable, and every time a scene is opened, a check is made to see which objects are replaced by another in that scene.

I’ve managed to reduce the steps into on line:

And then further down parse through the children of _visibiltyChange scene variable. It’s just one extra step, which I’m happy to wear.

I was just trying to decipher how to use this function, and I think I have it. Here is the code I used to test; hopefully it helps you. I intend to add something on the wiki for this.

1 Like

Your example is for scene variables. No equivalent exists for object variables, which I’m after. I’m already using this for child loop on the scene variable I create from the JSON conversion (see the snippet I’ve posted earlier).

BTW, the child name and value is not just child3 and 3. It goes though each child of node parent. So the child name & value pairings will be :

child name : child1
value : 1

child name : child2
value : 2

child name : child3
value : 3

1 Like