You could try to tweak your player var based on some condition too if you must have it embeded with the construction of the grid.
Use a bool maybe to turn player location on and off and it is only on when it’s in a spot, then if it’s not there it’s off and player location value is +0 and nothing is added.
Or a condition based on a negative operator.
If player location not there condition (excetera)
{ player location = 0; }
and var is changed to 0.
The smart way to do this is to make a copy of player location variable that does not affect player actual location and use that in your loop sintax. So the copy is for when you set it to zero not to affect the actual location of the player and this new variable handles adding or not adding to your grid line offset.
Now in your loop CopyVariablePlayerlocation.x will equal to zero, then nothing additional will be added.
If the condition is broken and player is at that spot then the value will add in the array, if not it will add +0 to array meaning nothing in addition.