Help with Tables in a Table (like a Dictionary)
I was wondering if someone could help me with a problem with adding a table to another table. I've seen something similar in the Lua tutorials as t[2] = { "apple", "pear", "banana" }.
In a nutshell, the below code generates a listing of the cards for each player around the table. Then, the values are to be put into the "players" table within the "hands" (in essence, players[1 to n].hand[MaxCards]).
Code:
function packDeal(params)
MaxSeats = packTable.MaxPlayers;
if #players < packTable.MaxPlayers then MaxSeats = #players end
local hands = {} ;
for p = 1, MaxSeats*tonumber(params) do
table.insert(hands,cards[1]);
table.remove(cards,1);
end
for i = 1, #hands do
CurrCount = 0;
while CurrCount <= MaxSeats do
CurrCount = CurrCount + 1;
-- XXXXX
table.insert(players[i].hand,{ hands[i * CurrCount] });
end
end
end
I receive the following error on the line indicated with the --XXXXX
Script Error: [string "scripts/chatmanager.lua"]:542: attempt to index field '?' (a nil value)
I've tried the code a few different ways, but I can't seem to get it to work. Any suggestions?
Thanks in advance!