How do I this: GlobalVariable(GlobalVariable(name))

How do I use the text inside of a variable as the name of the variable I want to retrieve?

Like this:
GlobalVariable(GlobalVariable(use-the-text-inside-of-this-variable-as-the-name-of-a-variable))

This is what I want to do:

  1. I have a variable that is a structure. It has many children, like “List.child1”, “List.child2”, “List.child3”, etc.
  2. The structure will eventually grow, so the variable might have hundreds of children.
  3. I use a variable called “random-number” to choose the name of the child that I want to retrieve from the structure. If the random number is “8”, a variable called “list-item-that-was-chosen” will have this text as its value: “List.child8”.
  4. How do I use the value of “list-item-that-was-chosen” as the name of the variable to call?

I tried this and it didn’t work: GlobalVariable(GlobalVariableString(list-item-that-was-chosen))

I tried many variations of that, and many other methods, and they didn’t work.

Here is the overall idea:

  1. a variable is called “random-number”. Pretend it equals 8.
  2. a structure variable is called “List”: “List.child1”, “List.child2”, etc.
  3. a variable called “list-item-that-was-chosen” will have this value: “List.child”+random-number, so it will say “List.child8”
  4. I want to know the value of the random child that was chosen, so I want to use the value of the variable called “list-item-that-was-chosen”, like this:
    GlobalVariable(GlobalVariable(list-item-that-was-chosen))

I need help with step 4.

Step 4 should become this:
GlobalVariable(List.child8)

How do I retrieve the value of the random child that was chosen?

I hope this would help, i had a lot of case like this. The syntax depends what you want to do exactly, with wich variable (object/scene/global) and type (number or text variables).

Basically, if i understand your problem, something like this might help you :
List[“child” + ToString(Variable(the_var_from_where_come_the_retrieved_value))]

List is the Global var/Structure, “child” is with double quote to specify it’s text and then i add a concatenation with another variable, wich use the value you want (for example 8).

1 Like

Kink solution should be enough to fix your problem, just want to note that your problem is that you save “List.child8” in the variable “list-item-that-was-chosen”, when you should save “child8”, this way you can do:

GlobalVariable( List[ VariableString(list-item-that-was-chosen) ] )
1 Like

That worked!

You are both true masters of life!

Thanks!