[Solved] Problem using "For every child in..." event

I’m trying to loop over some objects, and then for each object loop over a corresponding array in a Scene variable to create new objects. But the “For every child in…” event doesn’t seem to be working for me. I could use some pointers as to what I’m doing wrong. I’ve made a demo project showing the issue…

I have the following ‘placeholder’ objects in my scene, each with a ‘position’ variable set to ‘left’ and ‘right’ respectively:

I also have the following scene structure variable setup:

The goal here is to display text objects showing the numbers 12, 18 & 36 on top of the ‘left’ placeholder object, and the numbers 5 & 101 on top of the ‘right’ placeholder object.

Here are my events:

Unfortunately no text objects are displayed:

What am I doing wrong?

In here

image

child is the structure, in this case “left” or “right” with all it’s children.

You want the child name, the 3rd paramaeter in the For every child... event.

And it’s simpler to use VariableString(…), not ToString(Variable(…))


I suggest next time you run the game in debugger, and see what values the variables contain.

Thanks @MrMen, but I’m still confused…

My text object has a default value (“Initial text to display”) of ‘0’, so even if setting the text based on the ‘child’ variable isn’t working properly, there should still be text objects with ‘0’ displayed:

I disabled the setting of the text but it’s still not showing any text objects at all. I also added the third parameter as you suggested and checked the debugger, but it shows both ‘child’ and ‘childName’ as number type variables:

I don’t think the for each child can read the object variable for the [structure name]. I set a scene variable to the value of the object variable and it worked. I don’t understand what you’re doing with the random. So, I just tested it with a variable for the X().

This is my version:

When run I get this (I used an array/structure with left 1,2,3 and right 4,5,6
image

1 Like

That does indeed seem like the case! Thanks @Keith_1357, that’s solved it for me.

1 Like

I filed a bug report, as I feel like this should work the way I originally had it…

1 Like