Godot Version
4.2.2
Question
recently I have started making a game with my friend and I’m tasked with creating a slay the spire style map. I’ve been following a guide and managed to get the generation to work through but for some reason the array doesn’t follow the limit of 15 floors that I’ve set for it.
below is the bulk of the code that handles it. some help would be appreciated.
var random_room_type_total_weight := 0
var map_data: Array[Array]
func _ready() → void:
generate_map()
func generate_map() → Array[Array]:
map_data = _generate_initial_grid()
var i := 0
for floor in map_data:
print("floor %s: %s" % [i, floor])
i += 1
return []
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 = []
#boss room has a non random Y
if i == FLOORS - 1:
current_room.position.y = (i + 1) * -Y_DIST
adjacent_rooms.append(current_room)
result.append(adjacent_rooms)
return result
where the 15 floors limit you said you already set in your code? i dont see one?
const X_DIST := 30
const Y_DIST := 25
const PLACEMENT_RANDOMNESS := 5
const FLOORS := 15
const MAP_WIDTH := 8
const PATHS := 6
const ENEMY_ROOM_WEIGHT := 10.0
const SHOP_ROOM_WEIGHT := 2.5
const CAMPFIRE_ROOM_WEIGHT := 4.0
const SERIOUS_ENEMY_ROOM_WEIGHT := 5.0
const RANDOM_ROOM_WEIGHT := 2.5
const ITEM_ROOM_WEIGHT := 4.0
var random_room_type_weights = {
Room.Type.ENEMY: 0.0,
Room.Type.CAMPFIRE: 0.0,
Room.Type.SHOP:0.0,
Room.Type.SERIOUS_ENEMY:0.0,
Room.Type.ITEM:0.0,
Room.Type.RANDOM:0.0,
}
my bad but here it is
i see, so the problem here is, you set floor to 15 but somehow the code generate to 120?
yes, everything else is fine such as the map width since it is creating the 8 rooms as I specified but for some reason its not following the amount of floors I’ve set. should be 15 floors with 8 rows.
do you think it’s a coincidence that 15 *8= 120?
ahh i see so its multiplying the values together, just changed the floors to 2 and its got 16
i think this one need to remove 1 tab to the left

ok so thats solved the floors but now im not sure about why the other floors are blank except the last one
this one also need to remove 1 tab
THANKS SO MUCH

I’m new to Godot so I’m not familiar with how strict it is on layout
thank you for the help
indentation in gdscript matter, a single miss on that will break code or doing some weird stuff like this
i see that now. I’ve mainly done ue4 and ue5 so I haven’t had to think about it