compare 2 tables?

Posted by TruckDriver22 on Thu 12 Feb 2009 06:52 PM — 3 posts, 19,315 views.

Denmark #0
i have 2 triggers and i want the first trigger to capture targets for the 2nd trigger.
why dont it work?


trigger one!
rebash = rebash or {}
rebash ["%1"] = {"%1"}

trigger two!
stands = stands or {}
stands ["%1"] = "%1"
rebash = rebash {}
for sequence, priority in ipairs (rebash) do
for i, v in pairs (stands) do
if v == priority then
Send ("bash " .. v)
end
end
break
end
rebash = {}
stands = {}
USA #1
ipairs works on contiguously numbered indices, not keys. ipairs { 1,2,3, [5]= false, foo=true} loops thru [1]=1,[2]=2,[3]=3; but doesn't touch foo or [5] (since there's no 4 to keep the sequence intact).

So your ipairs(rebash) never iterates over anything.

You can fix that with

rebash = rebash or {}
rebash[#rebash+1] = "%1"

then 1=orc, 2=rat, 3=foo, which is probably what you want.

Amended on Thu 12 Feb 2009 10:05 PM by WillFa
Denmark #2
Thanks i found a much easier way to do what i needed it to do