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()
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 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.
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 :