Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | TKT |
var gridSize = Vector2( 5,5);
var gridArray = []
func _ready( ):
for x in range(gridSize.x):
for y in range(gridSize.y):
gridArray.append(Vector2(x,y))
func _physics_process(delta):
check_food_pos2():
func check_food_pos2():
var emptyTiles = gridArray
for tail in tailNodeArray:
emptyTiles.erase(pix2grid(tail.position))
emptyTiles.erase(pix2grid(get_node("head").get_position()))
print(gridArray.size())
var pos = emptyTiles[randi()%emptyTiles.size()]
food.position = grid2pix(pos);
I am trying to understand why my array (gridArray) changes its value in print. It should be constant after its first time. However it changes its value to emptyTiles. What do you think causing this and how should i prevent it?