Invalid Operands 'Array' and 'int' in operator '=='

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

I dont see the problem if anyone could help that would be great, please and thank you.

func build_level():
# Start with blank map

rooms.clear()
map.clear()
tile_map.clear()

level_size = LEVEL_SIZES[level_num]
for x in range(level_size.x):
	map.append([])
	for y in range(level_size.y):
		map[x].append([Tile.Stone])
		tile_map.set_cell(x, y, Tile.Stone)
		

var free_regions = [Rect2(Vector2(2, 2), level_size - Vector2(4, 4))]
var num_rooms = LEVEL_ROOM_COUNTS[level_num]
for i in range(num_rooms):
	add_room(free_regions)
	if free_regions.empty():
		break
		
connect_rooms()

Here are is the second Function where the problem keeps saying it is

func connect_rooms():
# Build an AStar graph of the area where we can add corridors

var stone_graph = AStar.new()
var point_id = 0
for x in range(level_size.x):
	for y in range(level_size.y):
		if map[x][y] == Tile.Stone:
			stone_graph.add_point(point_id, Vector3(x, y, 0))
			
			# Connect to the Left if also Stone
			if x > 0 && map[x - 1][y] == Tile.Stone:
				var left_point = stone_graph.get_closest_point(Vector3(x - 1, y, 0))
				stone_graph.connect_points(point_id, left_point)
			
			# Connect to the Above if also Stone
			if y > 0 && map[x][y - 1] == Tile.Stone:
				var above_point = stone_graph.get_closest_point(Vector3(x, y - 1, 0))
				stone_graph.connect_points(point_id, above_point)
			
			point_id += 1

# Build an AStar graph of room connection

var room_graph = AStar.new()
point_id = 0
for room in rooms:
	var room_center = room.position + room.size / 2
	room_graph.add_point(point_id, Vector3(room_center.x, room_center.y, 0))
	point_id += 1

# Add random connections until everything is connected

while !is_everything_connected(room_graph):
	add_random_connection(stone_graph, room_graph)
:bust_in_silhouette: Reply From: Zylann

Problem is in build_level():

func build_level():
    # Start with blank map

    rooms.clear()
    map.clear() 

map now contains []

    tile_map.clear()
    level_size = LEVEL_SIZES[level_num]
    for x in range(level_size.x):
        map.append([])

map now contains [[]]

        for y in range(level_size.y):
            map[x].append([Tile.Stone])

map now contains [[[Tile.Stone]]]
…and this is a 3D array. Notice the 3 brackets!
So if you access map[x][y], you get an array, hence your error when you expected an integer.

The fix:

            map[x].append(Tile.Stone)

Where Does that line of code go?

Dead_lucky_32 | 2019-07-17 22:10

for x in range(level_size.x):
    map.append([])
    for y in range(level_size.y):
        map[x].append(Tile.Stone) # <---- Here
        tile_map.set_cell(x, y, Tile.Stone)

Zylann | 2019-07-17 22:14

Thank you so much!! It now works and everything is fixed. I really apperate the help and it means a lot to me that you could help me!!

Dead_lucky_32 | 2019-07-17 22:15