combining variable names Syntax Help

Hey guys,
so my question is simple, im pretty sure its possible to do. In my game, depending on what level im on, i have a variable that is set to the number level. In my game logic file, i then am trying to get information from a global variable using the variable that holds the level number as well. I am trying to figure out the correct syntax to do this, here is what im currently doing.

[lua]–In a file named “global” i have
level0time = 0
level1time = 0
–And so forth

–Now in my game logic file…
levelNumber = 1 --For this example

levelTime = global.level…levelNumber…time --This is where i am in trouble[/lua]

can anyone shed some light on the correct way to do what im trying to do here?

thanks [import]uid: 19620 topic_id: 20367 reply_id: 320367[/import]

levelTime = global["level" .. levelNumber .. "time"]

You can also use the bracket notation to specify and access table properties that have non-identifier characters in them:

[code]
local myTable = {
Hello = “Hello World!”,
[“Goodbye!”] = “Goodbye World!”
}

print( myTable.Hello ) – Works fine
print( myTable.Goodbye! ) – Error
print( myTable[“He” … “llo”] ) – Works fine
print( myTable[“Goodbye!”] ) – Works fine
[/code] [import]uid: 71767 topic_id: 20367 reply_id: 79580[/import]

Wonderful, ive been wondering about this for a very long time, thank you so much! [import]uid: 19620 topic_id: 20367 reply_id: 79583[/import]

So now that you know how to do it the wrong way, you might as well learn how to do it the right way:

[code]
–In a file named “global” i have
levels = {
[1] = {
levelTitle = “Intro Level”,
time = 0,
},
[2] = {
levelTitle = “New Challenges”,
time = 0,
},
}
–And so forth

–Now in my game logic file…
levelNumber = 1 --For this example

levelTime = global.levels[levelNumber].time --Happily, I’m no longer in trouble.
[/code] [import]uid: 71767 topic_id: 20367 reply_id: 79733[/import]

Thank you for your help with this! [import]uid: 19620 topic_id: 20367 reply_id: 79771[/import]