Torros
24-10-2006, 08:12 AM
Hi,
I'm taking my first steps in writing an add-on and still struggling to get a good grasp on this .lua language. With all the sites and references I am making nice progress but there is one thing that keeps bugging me.
I just cannot seem to get my head around this whole table stuff. What I'd like is to create a multi dimensional table, use a charactername for key and a bunch of other attributes linked to that.
So I made a table with a characters name as key and another table as it's data.
I use this code for that:
--New Entry
tblReserves={[Sender]={Class="ClassData",Contact=Sender,Alternate="No",Note=".",AdminNote=".",JoinTime="Now"}}
That seems to work just fine. But no matter what I try I cannot seem to add another character to the table! When I revert the table to using numerical keys I will most probably get it to work but I would really like to get it to work this way. (I will never deny claims that I'm stubborn ;) )
I've tried adding the extra record with the following code (and more variations)
--Add Entry
table.insert (tblReserves,2,{[Sender]={Class="ClassData",Contact=Sender,Alternate="No",Note=".",AdminNote=".",JoinTime="Now"}});
table.insert (tblReserves,Sender,{Class="ClassData",Contact=Sender,Alternate="No",Note=".",AdminNote=".",JoinTime="Now"})
If anybody would be so good to point out the error in my way I would be very grateful.
Thanks,
Torros.
I'm taking my first steps in writing an add-on and still struggling to get a good grasp on this .lua language. With all the sites and references I am making nice progress but there is one thing that keeps bugging me.
I just cannot seem to get my head around this whole table stuff. What I'd like is to create a multi dimensional table, use a charactername for key and a bunch of other attributes linked to that.
So I made a table with a characters name as key and another table as it's data.
I use this code for that:
--New Entry
tblReserves={[Sender]={Class="ClassData",Contact=Sender,Alternate="No",Note=".",AdminNote=".",JoinTime="Now"}}
That seems to work just fine. But no matter what I try I cannot seem to add another character to the table! When I revert the table to using numerical keys I will most probably get it to work but I would really like to get it to work this way. (I will never deny claims that I'm stubborn ;) )
I've tried adding the extra record with the following code (and more variations)
--Add Entry
table.insert (tblReserves,2,{[Sender]={Class="ClassData",Contact=Sender,Alternate="No",Note=".",AdminNote=".",JoinTime="Now"}});
table.insert (tblReserves,Sender,{Class="ClassData",Contact=Sender,Alternate="No",Note=".",AdminNote=".",JoinTime="Now"})
If anybody would be so good to point out the error in my way I would be very grateful.
Thanks,
Torros.