Hi, I'm creating a roguelike game with dungeon generation similar to the binding of Isaac, I'm able to create a dungeon trying to fill each room with premade layouts, each room layout is a scene.

I had the idea to store each scene in an array that I pick a random one to instance in the location of each room.

when I do though I get this error code:

Am I missing something simple or is there another way to do what I want? is using scenes the best way to go about creating room layouts?

any help appreciated.

  • akaSkipper replied to this.
  • Darmanarnar Two possibilities how this would work if i am not mistaken.
    var rand_value = randi() % (scenes.size() - 1)
    or simpler just use
    var new room : PackedScene = scenes.pick_random()

    @synthnostate EDIT Oh yea you are right: var rand_value = randi() % scenes.size() would be if you index
    But still the problem isnt the indexing, but that youre loading the rand_value with a packed scene, and using a packed scene to index then scenes again.

    Darmanarnar Two possibilities how this would work if i am not mistaken.
    var rand_value = randi() % (scenes.size() - 1)
    or simpler just use
    var new room : PackedScene = scenes.pick_random()

    @synthnostate EDIT Oh yea you are right: var rand_value = randi() % scenes.size() would be if you index
    But still the problem isnt the indexing, but that youre loading the rand_value with a packed scene, and using a packed scene to index then scenes again.

      akaSkipper your code looks okay! maybe it is pulling the scene before it is ready? Arrays of objects don't always load in order.

      Uhh guys, @Darmanarnar has it right with randi() % scenes.size(). Modulo wraps around from zero to one minus its right side operand.

      I don't see any problem with using an array of scenes. You could also use an array of pathnames and load them when needed if they were too big to preload; I do that with 3D scenes.

        Imho, Array::pick_random() is simpler and more readable.