Godot Version
Godot 4.6.1
Question
Hi I followed Godot Game Lab tutorial for slay the spire map, godot crashes on for loop on Array of Arrays when trying to setup floor types
Array:
var map_data: Array[Array]
used cons:
FLOOR: int = 15
MAP_WIFTH: int = 7
populating this array
func _generate_initial_grid() -> Array[Array]:
var result : Array[Array] = []
for i in FLOORS:
var adjacent_rooms: Array[Room] = []
for j in MAP_WIDTH:
var current_room := Room.new()
var offset := Vector2(randf(), randf()) * PLACEMENT_RANDOMNESS
current_room.position = Vector2(j * X_DIST, i * -Y_DIST) + offset
current_room.row = i
current_room.column = j
current_room.next_rooms = []
if i == FLOORS - 1:
current_room.position.y = (i + 1) * -Y_DIST
adjacent_rooms.append(current_room)
result.append(adjacent_rooms)
return result
It uses resource of a Room:
extends Resource
class_name Room
enum room_list {NOT_ASSIGNED, start, weapon, ability, upgrade, rest_site, fight, boss}
@export var type: room_list
@export var row: int
@export var column: int
@export var position: Vector2
@export var next_rooms: Array[Room]
@export var selected: bool = false
Here’s the problem, Now I try to override type of each room according to some rules, but Godot freezes:
func _setup_room_types() -> void:
for room: Room in map_data[0]:
if room.next_rooms.size() > 0:
room.type = Room.room_list.fight
from what I managed to debug is that it goes through loop 7 times (which is equal to map width and correct behavior). It managed to change type of those rooms to “fight” and then never gets out of it. If I add breakpoint after loop it never reaches it. can anyone help with it?
Like I said, the bit issue is I don’t have any error, it just froze.
I use latest version, win 11 updated, gforce graphics updated and tried to restart godot, reload project, checked other places of the code and restarted pc. Also it’s seperate node from rest of the projects. There are more lines to this code of course, but it seems like those don’t change much to generate this issue