Log In  


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

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!


P#42510 2017-07-15 11:59 ( Edited 2017-07-16 04:32)

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
P#42517 2017-07-15 15:44 ( Edited 2017-07-15 19:44)

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!


P#42525 2017-07-15 19:59 ( Edited 2017-07-15 23:59)

Awesome! Glad it worked out for you ☺👍

P#42533 2017-07-16 00:32 ( Edited 2017-07-16 04:32)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2023-10-01 19:16:39 | 0.006s | Q:12