Local variables arrays set index aren't added[Bug]

I’ve been playing with the new local variables.

Wiki - Local Variables

They work as regular number, string and boolean. They also work as structures. I’m having trouble using them as an array.

When I assign values to the local array in the local variable event, I get a value of 0 for any index and it shows there are 0 children.

I discovered that if I add values to the array with actions then it works.

This should give me a result of “34”
(3 children in the array and 4 in the structure)

But it gives me a result of “14”
(1 child in the array and 4 in the structure)

I’m still undecided with the concept although I can see where it could reduce the number of variables in the other variable screens.

I think it would be nice with looping events like repeat, for each each child and for each object.

I wouldn’t want to over utilize it. There’s probably a slight decrease in efficiency with constantly adding and deleting variables but it would be good for setting up things and lighter events.

I wasn’t aware of local variable, and they’re something I could do with quite a bit.

What happens if you add a child to the structure variable? Does it return “11”? Or “15”? If the latter, then it suggests an inconsistency in application and maybe bug?

In my example. I have 2 children setup for the array. It doesn’t recognize them but it does work with children added through events. The variable exists otherwise I couldn’t add to it but unless I’m missing something it doesn’t seem to be working. They seem to have trouble with structures and arrays. It took them awhile to get things right when they simplified it the last time.

I agree. It would be nice for loops. It keeps the variable closer to the event and makes it easier to see what the values are and tweak them.

Also, structures work. It’s arrays.

The latest version has a lot of changes.

So that we don’t lose time investigating and debugging something that might not be a bug, please share a minimal project created from scratch showing the bug :slight_smile:

Something that has a few events using a local variable with an array, pushing something/modifying the array and then displaying it on a text for example. We’ll then take a look if there is something wrong. Thanks! :slight_smile:

1 Like

My original post has a screenshot of the events and variable setup. I simply declared a local array and tried to read the number of children. I also tried getting the value of variable[0]. It gave me 0 children and 0 for the child’s value. It didn’t matter if the array was a number, string or boolean.

Afterwards, I tried adding the variable with the action. That part works but the array only contained the child that I added and not the values on the setup screen.

The same technique using a structure variable works fine.

If you want a project, I’ll try to remember the next time I’m at my PC. But it’s just like 5 events.

I know this is just 5 events, but this allows us to just open it, verify in 1 minute there is a bug and then fix it often very fast.
We’ve observed in many cases that when asked, the reporter of the issue finds that the issue is slightly different and this allows to save time for the development team (no context switching, spend time working on new features rather than trying to reproduce the bug reports)

1 Like

Understood. I’m not at my PC. I’ll do it later when I have the time. This is a new feature. That’s why I posted this in the how do I section not bug.

Here’s my project:
https://github.com/doug13579/Gdevelelop-test-local-array-variable

Events

Result: I added 3 children to the Array but it shows as 0
image

Are there any updates on this? I just tested it with the online version. Default values do not get added to the array. You can add items to the array with actions but the initial values do not appear to be added or accessible.