Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
m (Changed layout slightly, corrected spelling)
(a string can not be called true! and it wasn't a boolean.)
Line 5: Line 5:
 
Example:
 
Example:
   
local random_array = { mug = "coffee", [42] = "universe", true = "false" }
+
local random_array = { mug = "coffee", [42] = "universe", testboolean = false }
 
 
 
for index,value in pairs(random_array) do
 
for index,value in pairs(random_array) do

Revision as of 19:48, 29 June 2009

Native Lua statement:

Used in loop constructs to iterate through the values of a table, with index being anything.

Example:

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.

Template:LUA