View Single Post
11/27/18, 11:29 PM   #10
Drummerx04
AddOn Author - Click to view addons
Join Date: Sep 2017
Posts: 54
Originally Posted by TheBunnynator1001 View Post
I'm brand new here, and I wanted to go ahead and voice this in my own words.
I've got a fairly decent grasp on Lua, and I wanted to start developing add ons for use on my client and potentially friends' clients as well. Unfortunately, I'm not entirely sure what I'm doing. I've read through some of the tutorials that are out there and they just don't compare to being able to ask questions and have them answered. My main question is this, is there somewhere I'm supposed to be putting functions within the code? Or can they be placed anywhere within the program? If you need more info on my add on to be able to answer, please feel free to PM me! I'd love to work with someone to learn more, and I could also use all the XML advice I can get! Thanks!
There is one thing to point out before I answer.

The Addon manifest (the .txt) file is used to specify a load order of the lua files and other assets of your Addon. So keep that in mind when you have multiple files and you use functions or tables between files.

A basic function declaration is in the global scope on all lines below the definition and in all files after its lua file is processed (and in game via /script)
Lua Code:
  1. function DoTheThings() return false end
This is only recommended for testing purposes to avoid collisions with other addons (unless that is your goal)

The best practice is to place functions within a Globally defined table unique to your addon. Declare the table in the first lua file specified in your manifest.
Lua Code:
  1. SpecialAddonTable = {}
  2. function SpecialAddonTable.DoTheThings() return false end

The "local" keyword will limit the scope of a declared variable/function to the scope in which it is declared
Lua Code:
  1. -- scoped to current file
  2. local function A()
  3.   -- scoped to function A
  4.   local function B(x) return x*x end
  5.   return B(5)
  6. end

The scope of a function can be limited to any block of code. Function names are just variables in Lua, so you can assign to or from them and they can also be nil.

That should be all you really need to know to get started. Start with one lua file (and the manifest). Load your addon into ESO and try calling the functions with /script use the d() function to print to the chat window.

Last edited by Drummerx04 : 11/27/18 at 11:32 PM.
  Reply With Quote