I have a couple quick questions about the information you gave me. In this:
Code: Select all
for k,v in pairs(table) do --this is 1 way to iterate over the table records
if (v) then --just being safe and testing that v is no null - should prolly check for table too but am being lazy
if (v.Npcname == npcToFind) then --could to a string.lower on this too to be safe
match=v; --set the match variable to the current row
break; -- stop iterating over the table and exit the for-loop
end;
end;
end;
if I were running two different searches on the same table to check for equality, would I have to use a different variable for "k", "v", and "match" on the second one?
Also, if a function calls another function, I am assuming the local variables from the first one won't be available in the second one, unless I use them in parenthesis when calling the function?
To be more clear, if I had used the functions like was in the second post:
Code: Select all
given:
function Func1()
--do some stuff
end;
function Func2()
--do some stuff
end;
function Func3()
--do some stuff
end;
function Func4()
--do some stuff
end;
local functions = { Func1, Func2, Func3, Func4 };
local i = 1; --index of the function to execute
--execute it
functions[i]();
Would I want to define the functions with variables using different variable names like this:
Code: Select all
function Func1(t_Npcname, t_Npcx, t_Npcz, t_Npcy)
--do some stuff
end;
then when I call the function, I would use something like this:
Code: Select all
functions[i](v.Npcname, v.Npcx, v.Npcy, v.Npcz);
Is that along the right lines?
Also had one question on this part:
Code: Select all
if (match) then
--do something with the npc. Note that 'match' is the row in the table, so match.NpcName will be "Mishlor" etc
-- e.g.
player:moveTo(CWaypoint(v.Npcx, v.Npcz, v.Npcy));
player:target_NPC(v.Npcname);
end;
if "match" is the matching row, then would I want to use "match.Npcname", "match.Npcx", etc... instead of "v.Npcname", "v.Npcx", etc...?
Thanks for the help.