Log In  


Hello,

Apologies, I am very new to this.

I'm making an old-school dungeon crawler, and I want to store info for each floor of the dungeon in a table, including intro text, player starting x,y coordinates and facing direction, etc. Then I would initialize each new floor with a start_floor(n) function where n = floor level.

So I have something like this:

floor1 = {
  text = "you descend the stairs."
  spawn = {x = 8, y = 6, dir = 1}
}

function start_floor(n)
  local fl = "floor"..n
  pl.x, pl.y, pl.dir = fl.spawn.x, fl.spawn.y, fl.spawn.dir
end

But it just doesn't like using the concatenated local "fl" -- if I switch that from "floor"..n to the correct fixed value (floor1) then it pulls everything from the table, no problem. But when it has to concatenate the floor number n, it the runtime error, "attempt to index local 'fl' (a string value)"

What am I missing, or misunderstanding? Any suggestions wold be greatly appreciated!

Thanks,
daggermoor



You could set it up so that you have a table that houses the floors and refer to it by number:

level = 1

floors = {{text='blah for floor 1', x= 60},{text='stuff floor 2', x=110}}

currentfloor = floors[level]

--when you move up to a new floor
level += 1

Thank you sloum!

I had tried something similar this morning but clearly I screwed it up, since yours worked like a charm out of the gate :)

Thanks again for setting me right!

-daggermoor


Awesome! Glad it worked out for you ☺👍



[Please log in to post a comment]