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.

    # Generate a height map for the room here and apply it to the room_instance
    # For a simple height map, just assign random heights to a 2D array or to visual elements within the room.

    add_child(room_instance)
    rooms.append(room_instance)


In the create_room function, there’s a comment suggesting where you would actually create and apply a height map for the room. You’ll need additional logic for generating and representing your height map within the Room.tscn scene.

The code block provided here is a starting point. You will need a concrete implementation of the height map logic as per your game’s design. The representation of the height map and its usage could greatly vary based on whether you’re making a 2D platformer, a top-down game, or a 3D dungeon crawler, so you should adjust the code according to your specific needs.

Also, methods such as create_platformer_view_for_room, on_room_entered, and on_room_exited are placeholders for you to expand upon. Depending on the complexity of your dungeon and how you want to handle room transitions, you’d fill in these methods with relevant code. For example, create_platformer_view_for_room might add platforms and obstacles within the room using procedural generation or by placing pre-built elements based on the room’s size.
show me the script for the room.tsc