Text Adventure

Thanks @dave1707. One more thing I need to check after looking over integrating what I’ve already done… I had rooms set up in a table like this…

room[1]={n=4,s=0,e=2,w=0,u=0,d=0,name="FOREST",desc="#1 You are lost in a dark, dense forest."}

which meant I could easily reference the room number eg north here takes you to room[4].

I discovered that I can’t use labels for directions so I need to change the direction data to just numbers eg 4,0,2,0,0,0. But what has me puzzled atm is how best to now reference the appropriate room if they are just called rm1, rm2, etc. So do I need to include a room index in the data as well, so it becomes

function Room:init(number, name, mapData, objects, description)

@David Instead of using rm1, rm2, etc, you can continue to use a room table. In my example code above where I say rm1=Room(…) you can use room[1]=Room(…) or table.insert(room,Room(…)).

@David Just in case you need an example.


--# Main
-- Classes

function setup()
    room={}
    room[1]=Room("Dungeon",4,0,2,0,0,0,{{"Key",1,0},{"Lamp",3,1},{"Rope",6,0}})
    room[2]=Room("Passage",2,1,3,2,2,4,{{"Key",2,0},{"Lamp",1,1},{"Rope",2,0}})
    for a,b in pairs(room) do
        print(b.name)
        print(b.north,b.south,b.east,b.west,b.up,b.down)
        for c,d in pairs(b.objects) do
            for e,f in pairs(d) do
                print(f)
            end
        end
        print()
    end
end

function draw()
    background(30,30,30)    
end

Room=class()

function Room:init(name,n,s,e,w,u,d,objects)
    self.name=name
    self.north=n
    self.south=s
    self.east=e
    self.west=w
    self.up=u
    self.down=d
    self.objects=objects  
end

Wow @dave1707 that is absolutely brilliant, thank you! I’d tried using room[1] myself but had forgotten to set it up with room = {} first. That works perfectly for what I wanted to do. :wink: