lua:scripting
Table of Contents
Lua
Lua in WoW
/reload– Reload plugin directories/console scriptErrors 1– Enable lua errors/console scriptErrors 0– Disable lua errors/etrace– Open event trace/fstack– Toggle Frame Stack debugging
Cheat sheet
Conditions
- < (less than)
- ⇐ (less than or equals)
- > (greater than)
- >= (greater than or equals)
- == (equals)
- ~= (not equals)
- and
- or
- not
Variables
Type depending on assignment. String, number and boolean.
local a = "Yo man's dude" -- locally scoped b = 432.12 -- global
Tables
greetings = {} greetings["Orcish"] = "Throm-Ka" greetings["Draenei"] = "Chronakai Kristor!" greetings.Thalassian = "Bal'a dash, malanore" -- Another method to fill the table
greetings = { ["Orcish"] = "Throm-Ka", ["Draenei"] = "Chronokai Kristor!", ["Thalassian"] = "Bal'a dash, malanore" } for key, value in pairs(greetings) do print("Language: " .. key .. ", greeting: " .. value) end
number = 1 potencies = {} while(number < 4096) do number = number * 2 table.insert(potencies, number) end print("Our table has " .. #potencies .. " entries.") print("The tenth potency of 2 is " .. potencies[10] .. ".") print("The first " .. #potencies .. " potencies of 2:") for i = 1, #potencies, 1 do print(potencies[i]) end
Loops
i = 1 while(i <= 10) do print(i) i = i + 1 end
for i = 1, 10, 1 do print(i) end
for var = start, end, increment do -- code end
repeat -- code until(condition)
Functions
function dummy() return "Hey", 54.54 end
Examples
-- Create a frame and register this frame to run code on an event. local function PrintStuff() print("Now this code is executed!") end local EventFrame = CreateFrame("frame", "EventFrame") EventFrame:RegisterEvent("PLAYER_ENTERING_WORLD") EventFrame:SetScript("OnEvent", function(self, event, ...) if(event == "PLAYER_ENTERING_WORLD") then C_Timer.After(1, PrintStuff) end end)
lua/scripting.txt · Last modified: 2022/11/12 22:12 by utedass
