you gave an error but here is the message before it crashed: It looks like you have a…
- User
you gave an error but here is the message before it crashed:
It looks like you have a good setup for generating random rooms with various sizes and positioning them within a given map size. However, your script seems to lack several key aspects to make it fully functional. For instance, the provided Room class is not actually created as a Node (so it doesn’t integrate with Godot’s node system), and there are method calls for setting up rooms which do not exist in the provided Room class (set_room_size and the like).
Also, the way you are instantiating the rooms suggests that Room.tscn should have a script attached to it which can handle methods like set_room_size. Here’s an assumption on how Room.tscn’s attached script may look like:
extends Node2D
var size = Vector2()
func set_room_size(new_size): size = new_size # Here, you would add your logic to use the provided size to shape the room node # typically this would imply resizing sprites, collision shapes, etc.
To get your script running, you’d also need to ensure the class Room code uses Godot’s node system, which your current pseudo-code does not yet. Let’s adjust the Room definition within your script to make sure it matches the structure expected by a PackedScene (which Room.tscn is):
Since your script expects to generate a “height map,” you need additional logic to create a height map for each room or the entire dungeon. However, without a clearer understanding of how you want to handle the height map (e.g., as a visual or collision element, as a fully 3D height map or a 2D representation), I’ll provide a general setup to include a 2D height map for each room, which can be expanded upon for more complex use cases.
Let’s adjust the code to work with a simple version of Room.tscn that can handle size settings:
extends Node
var max_rooms = 10 var room_min_size = Vector2(5, 5) var room_max_size = Vector2(10, 10) var map_size = Vector2(100, 100) var rooms = [] var room_scene: PackedScene = preload(“res://Scenes/Room.tscn”)
func _ready(): print("Preloaded room_scene is: ", room_scene) if room_scene is PackedScene: print(“Confirmed that room_scene is a PackedScene”) generate_dungeon() else: print("room_scene is not a PackedScene, it is: ", room_scene.get_class())
func generate_dungeon(): var rng = RandomNumberGenerator.new() rng.randomize() for i in range(max_rooms): var room_width = rng.randi_range(int(room_min_size.x), int(room_max_size.x)) var room_height = rng.randi_range(int(room_min_size.y), int(room_max_size.y)) var x = rng.randi_range(0, int(map_size.x) - room_width) var y = rng.randi_range(0, int(map_size.y) - room_height) var room_pos = Vector2(x, y) var room_size = Vector2(room_width, room_height) create_room(room_pos, room_size)
func create_room(position, size): var room_instance = room_scene.instance() room_instance.set_room_size(size) # Assume Room.tscn’s script handles the size and visual representation. room_instance.position = position # Assume the position in the script is handled in grid units or directly in pixels.
- Assistant
The script provided in your message appears to be for the generation of rooms within a Godot game engine project, but the corresponding script for the scene itself is not included. Based on your description, I can give you an example of what the script () attached to might look like, including a method for setting the room size. Note that the actual implementation will depend on your game's specific requirements and the properties you've defined in your scene.
- User
complete it for me with added tilemap and so on
- Assistant
To create a more complete script for a that uses a and adjusts based on the provided room size, you can build upon the given example. Below is a script that could be attached to a scene root node (). This script assumes you have a as a child of the scene for the floor of the room.