variables acting weird

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ROBOTOO007

i have this code running:
EMPTY = “o”
so map should be equal to a bunc of lists all filled with “o”
but it’s the same as map_coord i don’t know why that is

func createMap() -> void:
	for x in range(map_size.y):
		for y in range(map_size.x):
	map_coord = map
	var screen_Div_map_size = get_viewport().size / map_size
	for x in range(map_size.y):
		for y in range(map_size.x):
			map_coord[x][y] = Vector2(screen_Div_map_size.x * y, screen_Div_map_size.y * x)
:bust_in_silhouette: Reply From: kidscancode

This is your problem:

map_coord = map

Arrays are passed by reference so, you’re now changing the original array. Use

map_coord = map.duplicate()

if you want a unique copy.

for some reason that still didn’t fix my problem thanks for helping out though :slight_smile:

ROBOTOO007 | 2020-05-21 18:53

:bust_in_silhouette: Reply From: ROBOTOO007

OH okay so duplicate works i just did a little research and had to put true in the parentheses