User Tools

Site Tools


lua:scripting

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
lua:scripting [2022/11/12 14:37] utedasslua:scripting [2022/11/12 22:12] (current) – [Examples] utedass
Line 1: Line 1:
 ====== Lua ====== ====== Lua ======
  
 +
 +  * [[https://www.wowhead.com/guide/comprehensive-beginners-guide-for-wow-addon-coding-in-lua-5338| WoW Lua guide]]
 +  * [[https://www.lua.org/cgi-bin/demo|Online Lua demo]]
 +  * [[https://lua.org/pil/contents.html|Lua documentation]]
 +  * [[https://wowwiki.wikia.com/wiki/WoW_AddOn|Wow addons]]
 +  * [[https://wowprogramming.com/|Wow programming]]
 +  * [[https://wow.gamepedia.com/World_of_Warcraft_API|Wow API guide]]
 +  * [[https://authors.curseforge.com/forums|Wow plugin]]
 +
 +====== 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
 +  * [[https://wowwiki-archive.fandom.com/wiki/Events_A-Z_(full_list)|WoW events]]
 +  * [[https://wowpedia.fandom.com/wiki/TOC_format|.toc format]]
 +  * [[https://wowpedia.fandom.com/wiki/Frame_Strata|Frame Strata]]
 +  * [[https://wowwiki-archive.fandom.com/wiki/AddOn_loading_process|AddOn loading process]]
 ====== Cheat sheet ====== ====== 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.
 +
 +<code lua>
 +local a = "Yo man's dude" -- locally scoped
 +b = 432.12 -- global
 +</code>
 +
 +===== Tables =====
 +<code lua>
 +greetings = {}
 +greetings["Orcish"] = "Throm-Ka"
 +greetings["Draenei"] = "Chronakai Kristor!"
 +greetings.Thalassian = "Bal'a dash, malanore" -- Another method to fill the table
 +</code>
 +
 +<code lua>
 +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
 +</code>
 +
 +<code lua>
 +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
 +</code>
 +===== Loops =====
  
 <code lua> <code lua>
--- Loops 
 i = 1 i = 1
  
Line 11: Line 89:
     i = i + 1     i = i + 1
 end end
 +</code>
  
 +<code lua>
 for i = 1, 10, 1 do for i = 1, 10, 1 do
     print(i)     print(i)
 end end
 +</code>
  
 +<code lua>
 for var = start, end, increment do for var = start, end, increment do
     -- code     -- code
 end end
 +</code>
  
 +<code lua>
 +repeat
 +    -- code
 +until(condition)
 </code> </code>
 +
 +
 +===== Functions =====
 +
 +<code lua>
 function dummy() function dummy()
     return "Hey", 54.54     return "Hey", 54.54
 end end
 +</code>
 +
 <code lua> <code lua>
  
 </code> </code>
 +
 +===== Examples =====
  
 <code lua> <code lua>
 +-- 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)
 </code> </code>
lua/scripting.1668263828.txt.gz · Last modified: 2022/11/12 14:37 by utedass

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki