How do I fix this array issue?

How do I…

How do I make a value get added to an array at the push of a button?

What is the expected result

When I press the up arrow, the controls external event sheet states that the value 1 is to be added to the player object’s array, “action,” which is empty at the start of the scene. Whenever the object boolean “tick” is true, the value at child 0 of the “action” array is read, and in this case, is interpreted to mean “move 8 px upwards,” based on the external events sheet “movement.” After receiving this info, the player object removes child 0 from the array, causing child 1 to take its place, and so on down the line. I’m pretty sure.

What is the actual result

The interval-based turn system, established in the external event sheet “tick intervals” works, so far. But only for adding 45-degrees to the object’s angle whenever “tick” is true. However, this new system of sending commands to the player object’s to-do list array doesn’t seem to work. When the arrow key is pressed, the text object that’s supposed to display the value of entity.action[0] only displays “0,” and the player object doesn’t do anything.

Related screenshots

Hi it looks like you’re adding 1 to actions of entity when it needs to be added to specific child actions[0] of entity

Then how do I create a new child with a value of 1 on the end of entity.actions? Because that’s what I’m trying to do. As I said, it should create a to-do list for the player object, using that array.

According to this video: Variables In GDevelop Expanded - Structures And Arrays, adding the value 1 to array Actions of entity is executed correctly. Which means the issue must be elsewhere.

I don’t know if this is the issue but just trying to read an array index will create it if it doesn’t exist. Before you check the value of index zero make sure the size of the array isnt zero.

Edit …sorry I hadn’t seen Keith’s reply, and I hadn’t fully digested what you were up to! I’ll leave it to Keith

No worries. Feel free to chime in. I’m at work and won’t be replying often.

1 Like

It’s always less of a ‘chime’ and more of a clong!

1 Like