Inconsistent variable types when using expressions in nested arrays

These are the variables in the scene:

The variable lists[1].B is a text, but if I use the expression lists[current_list][current_letter] that leads to the same variable, the action forces it to be boolean, and it doesn’t even show an option to “use as…” text.

It might be because the first child variable of the first structure inside the lists array is boolean. When I changed the type of that variable to a “number”, the action also changed to “Modify the number value of a variable”.

The same happened in conditions too.

If the option to define the variable type appeared in this case it could be helpful.

2 Likes

I briefly mentioned this in my last post, but you nailed it.

I’ll make a link to yours.

1 Like

Usually, there are 2 use cases:

  • Either you want to access structures or arrays dynamically (with a variable as index) and the children types need to be the same. Otherwise, how can you loop on them?
    • MyStructure[MyIndex]
  • Or you want to access a structure directly (without using a variable as an index) and it makes sense to have children with various types.
    • MyStructure.MyChild

Why do you need a mix of both?

1 Like

In a lot of cases I need an array of structures.

1 Like

Which is totally fine. It’s not what I meant by mix of both.

When you access children with a variable like this: MyStructure[MyIndex] every child must be the same type otherwise you don’t know what you get.

In the example given by @dep, the array contains children with type {enabled: Boolean} or {A: Text, B, Text, C: Text, D: Text}. I don’t see how this array can be looped with events as you don’t know what to expect in the child.

1 Like

Unless I’m misunderstanding, I think the issue being described in the original post isn’t about looping or using different types in the same event, it’s about the condition/action itself not selecting the right typing. Therefore it shouldn’t matter about looping through the variables.

They are trying to use a condition explicitly to check strings, but due to the collapsing of all variable conditions/actions into a single condition/action that tries to be dynamic, there is now a new problem where game devs can no longer use a mixed type structure since it seems to be detecting the wrong type of child variable. Mixed type structures (or multi level arrays) are extremely common in a lot of game dev especially when there’s no support for databases. The ask seems to be for a way to use a string condition/action on a dynamically selected structure child, especially since they know it is a string.

The fact that the new system makes this more complex to design for isn’t an issue for the OP to solve, but an issue from the new system that likely needs to be resolved at the design level of the engine. Maybe an option on the event condition/action that lets you override the detected/assumed variable type?

3 Likes

Exactly, and I’m sure the functionality is right there (like it used to be), but hidden behind a bad design choice.

It’s an issue related to how the new actions are designed and how it limits the GDevelop core capabilities.

2 Likes

It seems to work:

image

1 Like

Mine changed right before my eyes. But I set it up like the OP that the first structure had one bool child.

2 Likes

This boolean is likely a hack to start at questions at number 1. If this is the case, it’s not a good idea to do this as it will lead to events that are hard to read and prone to bugs.

The 1st array child (0) should be used. The question number can be displayed using an expression like this "Question #" + ToString(MyIndex + 1).

1 Like

I agree, that is how I would have done it. But it’s still odd how it changed like that.

1 Like

I guess that for arrays at least, the variable editor could warn about about mixed children types.

1 Like

I know this topic is old (I’m sorry), I took a break from working on that and only came back recently.

The first structure will actually be used to store information about the quiz as a whole and not about individual questions, and I put that inside the array so it can be saved together with the questions in a JSON file.

Basically I have 4 text input objects, each with a variable containing it’s option letter, and when I press save it loops for each object saving it’s text on a variable named with it’s option letter inside the structure:

But because of that boolean variable in the beginning I can’t change the variables as text, the action forces it to be boolean.

I’ve found a workaround by adding an empty array or structure as the first child (and removing it at the beginning of the scene) and it finally let me choose between the variable types

But I feel like I shouldn’t need that array for the option to appear.

1 Like

You should put your option content in a dedicated structure something like this: questions[editing].options[option.letter]

1 Like

Ok, that’ll work for now, thanks

1 Like