Dynamically creating child variables in a structure (without it creating them as arrays)

So I’m trying to dynamically create some character data in a global structure variable to save myself some tedium later down the line, but I’m finding myself a little stumped.

Basically, the game I’m tinkering with is supposed to have multiple different characters, each with their own info, stats and potentially their own inventories and the like. So to organise all this data I created a global structure, with each character as a child structure of that structure, with all their info and data as variables of those child structures. It works well, except I plan to have quite a big cast, and I wanted to streamline it a bit and instead of recreating every variable for each new character by hand in the variable editor, I’ve tried to make a custom action (in a custom extension) to create all variables dynamically, as a template of sorts so I don’t have to click so many buttons and not risk forgetting a variable.

This is how the events in the custom action looks;

The problem is that instead of creating plain number and string variables within the character’s like I expected it to, it seems to add the value of those new variables as a child array of said variables instead of just… well, a direct value of that variable.

Here’s a debugger screenshot that shows what I mean;


The “Test” structure is the one whose values has been dynamically created. The child variables of the “Novalie” structure above it is created manually in the variable editor, I left it’s “bio_age” variable open to show what I was hoping to achieve. You can see the bio_age of Novalie does not have an array nested within it, unlike Test.

Now, it does work to add a “.0” at the end of the expression for retrieving the value, so I guess technically it’s not that it doesn’t work? It’s just… doing it in a kinda weird and ugly way, and honestly it’s just bothering me too much lol

Is there something I’m doing wrong here, or is this just how it’s supposed to work?

You’re adding the variables to an array. Instead you need to set the values of the variables using the variables and children names like player.name.Age

This uses an extention variable

And these parameters

These are the action events

And the scene action using the scene structure variable Players (it could also be global)

This allows you to use it with any variable.

.
You could use a parameter as an identifier. It creates an autocomplete field that suggests previous values

The action would list the previous cities.

Or create a predefined list for type

Click to select type.

that worked! Thank you! :smiley:

1 Like