[Solved] Can't set an arrays value to 0

Hi!

I am making a ludo game. The gameboard is made out of two arrays, one for x values and one for y values (playerxPos and PlayeryPos). They “depend” on the variable currentPos. When currentPos = 1 playerxPos[currentPos] = 587. The outer “circle” is 40 blocks long and when a player has moved a lap around the entire thing it should restart from 0 so it can continue as all colors use the same array, but my way doesn’t seem to work and I have no clue why. It works if you just roll 1s all the way around, but as soon as you roll anything else the player is moved to the top left corner (0,0) after passing square 40 instead. If I then click on the player again, it moves to the correct square. Why doesn’t my current code work and how can I make it work?

This is happening because you are increasing currentPos and updating the X & Y positions before you check that the current pos is greater or equal to 39.

So the first action of this :

is setting the currentpos[…] to 39, and then updating the X & Y positions with array values that don’t exist. So GDevelop creates them and defaults them to 0.

Only after the repositioning actions have occurred does this get actioned :

I think that is intentionally placed there, but I had just forgotten to move the actual object. I changed the values but never moved the object. The placement could be wrong too, but I think it’s working properly now.