Wikia

WoWWiki

API pairs

Talk0
102,035pages on
this wiki
Revision as of 07:49, September 19, 2013 by Celess22 (Talk | contribs)

(diff) ←Older revision | Latest revision (diff) | Newer revision → (diff)
WoW Lua

Returns an iterator triple that allows for loops to iterate over all key/value pairs in a table.

iteratorFunc, table, startState = pairs(table);

Example Edit

local random_array = { mug = "coffee", [42] = "universe", testboolean = false }

for index,value in pairs(random_array) do 
  if (type(index) == "number") then
     index = tostring(index)
  elseif (type(index) == "boolean") then
    if (index) then
      index = "true"
    else
      index = "false"
    end
  end
  DEFAULT_CHAT_FRAME:AddMessage(index.." : "..value)
end

Result:

 mug : coffee
 42 : universe
 true : false

would be output to the chat window.

Around Wikia's network

Random Wiki