#Godot just crashes after generating a procedural dungeon
1 messages · Page 1 of 1 (latest)
Here is how it works:
I have a grid map that is filled with some cubes. These cubes are going to be my sketchup for the dungeon itself
But I need to generate them first, before moving to the dungeon
Wheneven I click the button to create it, the engine just closes without any popup or any error mensage
The code that works:
@tool
extends Node3D
@export var start : bool = false : set = set_start
@export var border_size : int = 20 : set = set_border_size
@export var min_room_size : int = 2
@export var max_room_size : int = 8
@export var room_margin : int = 1
@export var number_of_rooms : int = 4
@onready var grid_map: GridMap = $GridMap
func set_start(set: bool)->void:
generate()
func set_border_size(val : int)->void:
border_size = val
if Engine.is_editor_hint(): #checks if is in the editor or in the game itself
visualize_border()
func visualize_border(): # shows the border of dungeon
print("Showing borders, current border size is: ", border_size)
grid_map.clear() #clears the meshes before showing, this prevents to paint on top of the new border visualization, comment this line to understand what does it does
for i in range(-1, border_size+1): # draws the borders
grid_map.set_cell_item(Vector3i(i, 0, -1),3) # draws in X axis
grid_map.set_cell_item(Vector3i(i,0,border_size),3) # in Y axis
grid_map.set_cell_item(Vector3i(border_size,0,i),3) # in X axis
grid_map.set_cell_item(Vector3i(-1, 0, i),3) # in Y axis, put a negative number to understand whats going on here
func make_room():
var width : int = (randi() % (max_room_size - min_room_size)) + min_room_size
var height : int = (randi() % (max_room_size - min_room_size)) + min_room_size
var start_pos : Vector3i
start_pos.x = randi() % (border_size - width + 1)
start_pos.z = randi() % (border_size - height + 1)
for row in height:
for column in width:
var pos : Vector3i = start_pos + Vector3i(column, 0, row)
grid_map.set_cell_item(pos, 0)
func generate():
print("Generating. . .")
visualize_border()
for i in number_of_rooms:
make_room()
And the one that doesnt
htt ps://copy-pa ste.onl ine/?code=9009
I've been struggling with this for a few days now, any idea?