Stupid Lua Question - Concatenation of Table Name

Stupid Lua Question - Concatenation of Table Name

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Stupid Lua Question - Concatenation of Table Name

Post by Argh »

Basically, I want to do something where I have table0, table1, table2, etc.

I want to refer to those tables by getting a value and matching that with the rest of the table name. However, it seems that table..X doesn't work. How do I correctly address that table?
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Stupid Lua Question - Concatenation of Table Name

Post by lurker »

Seriously? You can't just put them in another table? But okay, as long as they aren't local:
real_G = getfenv()
table = real_G['table'..X]

I worry that I shouldn't be telling you this.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Stupid Lua Question - Concatenation of Table Name

Post by Argh »

Meh, I'm just trying to avoid a lot of very tedious copy-pasta, basically. Oops, I meant, "oh, my super-secret project requires that I need this". I didn't realize this was non-trivial, tbh, I just figured I was a little slow this evening.

Can't I just get the current index for the table, by getting the [0] value? Or is what you're showing me the only way to make it work? I don't really need this stuff to be global.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Stupid Lua Question - Concatenation of Table Name

Post by lurker »

Argh wrote:Meh, I'm just trying to avoid a lot of very tedious copy-pasta, basically.
And you cant do that by making a big table with your little tables in it? supertable = {[1] = {}}
Argh wrote:Can't I just get the current index for the table, by getting the [0] value?
That... physically hurt.

The table variable IS the index, you crazy man.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Stupid Lua Question - Concatenation of Table Name

Post by Argh »

:roll: What can I say? I hate fricking tables, and whenever I try to nest them, horrible things usually result. It's the one part of Lua that never gets any more fun for me.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Stupid Lua Question - Concatenation of Table Name

Post by Argh »

<pant, pant>

Ok, multiple tables are finally working. Moving on, to the easy part...
Post Reply

Return to “Lua Scripts”