[Solved] Accessing a child

I created a child dinamically this way:
Do=RandomInRange(1,5) to global variable number
Condition:
Child GlobalVariableString(number) of global variabe list exists (inverted condition)
Action:
Do=1 to global variable list.GlobalVariable(number)

Doing that am I creating a child (1 to 5) to variable list and assigning the value 1 to it?
What’s the correct command to check if the child has been created?

I have an event to be triggered if the child exists, but i’ts not being executed.
Wiki didn’t help me!
Thanks!

No it is not the right way to do it. This is how you can do it:

Do = 1 to global variable list[ToString(GlobalVariable(number))]

If the value of number is 5, then it is going to create the child named 5 and set the value of this child to 1.

There is an event to check if a child exist.
For child name, enter the expression: ToString(GlobalVariable(number))
And then do something if exist, change a text…etc

You can also use the debugger to check if the variable has any childs and the values.

You can also simply check the value of list[ToString(GlobalVariable(number))] if = 1 or not. If = 1, then it is exist otherwise it is going to return 0, and again you can do something like changing a text…etc if the value = 1…

Many thanks! I knew I was doing something wrong. Gonna do what you said and post the result.

OK! I tried that, but there’s something wrong yet!
I guess this code should create 1 child each click. Or not?
Debugger shows it creates sometimes 3 children at once, sometimes none for each click.

You need to use the trigger once condition to make sure it fires only once each time you press the mouse button. It should fix the problem with creating multiple childs at once.

Regarding creating no child at all, that could be because the child already exist maybe? So you have a child with the name “5” and if the value of sorteio is 5, it is already exist so it won’t create a new one.
You can’t have multiple childs with the same name.
If you need a new child every single time you click the button, increase the range to 1-1000 or something and you may also want to use a While loop to get a random number until find one that does not exist already in lista.

So you can try something like this:

Left mouse button was released : 
The Cursor touch is on NewObject3

Do = RandomInRange(1,1000) to global variable sorteio

While
Child ToString(GlobalVariable(sorteio)) of global variable lista exist : Do = RandomInRange(1,1000) to global variable sorteio

After the While
Child ToString(GlobalVariable(sorteio)) of global variable lista DO NOT exist : Do = 1 to global variable lista[ToString(GlobalVariable(sorteio))]

2 Likes

Thanks again!
Trigger once didn’t solve the problem.
It’s too late night now where I am. I´ll try it tomorrow.
Have a nice time!

Bingo!!! “While” function solved the problem like a charm! Thank you very much for your attention and spent time. Some people have no much patience at all in this forun. But I was lucky my post has been replied by you. I always see your posts, replying doubts and I admire the way you do it. Keep acting like that. Sometimes a question can be simple or even “stupid” for who knows the answer, but not for who do it.
Hope you have a excellent day!

I know I have anger management issues when dealing with some persons on this forum. I am trying to correct that problem of mine. Sorry if I ever bothered or bother you again.

No arthuro! I was not talking about you. We never had any issues, and I hope it keeps going this way. I’m a paceful person and I like to teach what I know, no matter how many times I have to do it. People are different each other. Everyone have their own capacities of understanding, and we have to deal with this. If you know you have this personality, try to change and be polite and kind. I’m sure you will feel yourself much better. Have a nice day! God bless you!

Hi zutty. I am also trying to do a random questions without repeat. Can I see how you did this?

Hi! Here is how it works:

You can use arrays now, you can make it way easier and cleaner using those.

Yes! The time I did that, there was no array resource. Thanks!

The no repeat works but it’s spitting out the random number not the actual question. What text should I set my TextBox to?


image

It’s not working. The value of the child variable is turning to zero on each click.
image

Post a print of your code.

Use this code instead. That one was my first try. This works better:

Or use arrays:

Set variable index to RandomInRange(0, VariableChildCount(questions) - 1)
Set text of object question to VariableString(questions[Variable(index)])
Remove index Variable(index) of array questions