"Insert Variable At" Action - How do I change it?

I have an array of 42 cells (game of 4-in-a-row).

When I’m using the “Insert Variable At” action, it is adding a new cell to the array and also pushes all the cells that comes after it.

The expected behavior (or what I want to achieve) is simply to insert the value of the current player (either 1 or 2) to a specific cell in the array (to reflect the state of the board), without changing all other cells and without adding new cells to the array.

How do I achieve that?

Thanks!

If you want to set a value of an array index then just set the value. Array elements don’t need to be created. They’ll add themselves when set or read. The variable itself should be declared as an array otherwise it might be created as a structure. There aren’t that many differences between arrays and structures.

In your case, you might want to use an array of arrays. (This is also called multidimensional) With an array of arrays you could use column and row indexes.

Example setup for an array and an array of arrays. You. Can easily setup an array of arrays using copy and paste.

Note: if you create say list[4] then list[0] thru list[3] get created with a null value if they don’t already exist.

Well first of all thank you for your response. :slight_smile:

But maybe I wasn’t clear enough. I’m trying to change the value of a specific index in the array, where this index is a variable. This is why i’m using the “Insert variable at”.

Example: I need to update cell (X), so if X=4 then cell 4 will be updated. I don’t want to directly/manually update cell 4. I want the index to be a variable.

If you want to use a variable instead of a number then replace the number with the variable name.

Set Grid[x] to 10
Set Grid[x] to CurrentPlayer

(CurrentPlayer would be a numerical variable)

Pretty much anywhere a number or string is used, a variable of the matching type can be used.