Originally Posted by justinbarrett
EDIT: ty for the link and the info. I'll be sure to look at it now.
ok looking through some code it seems the basic function is closed with "end"...
so..
function thisFunction()
do stuff here
end
is a basic function, as far as I can tell....
and local variables are simply
"local a = 0 "
I still cannot see how global variables are done though. I did see at the top of a few scripts something that could be an array, or list...not sure. I thought maybe things could be stored in them, but hey...noob here
|
Yes, that is a function and they are closed with the end statement.
Lua Code:
function addFunction(value1, value2)
return value1 + value2
end
A local variable would be defined with the word local:
Lua Code:
-- this variable is local
local counter = 1
If you want a global you just leave off the word local
Lua Code:
-- this variable is global
counter = 1
The thing you mentioned that looked like an array was a table. They have no pre-defined size, you just put stuff in them.
Lua Code:
-- This is an empty table (has nothing in it):
myTable = {}
You can put stuff in your table in more than one way, one example would be while you are creating the table:
Lua Code:
myAddon = {
-- Notice the commas at the end of each statement in the table
-- Put my addons name in the table:
addonName = "My Addon",
-- Put a function in the table:
fun1 = addFunction,
-- Put another table in here:
someTable = myTable,
}
They can then be accessed by calling:
Lua Code:
myAddon.addonName -- returns My Addon
myAddon.fun1(1, 2) -- returns 3
-- ... --
Items can also be placed in tables by an integer index:
Lua Code:
myTable = {
[1] = "My Addon Name",
[2] = "something else",
-- .... --
}
And then called upon by doing:
Lua Code:
myTable[1] -- returns: My Addon Name
myTable[2] -- returns: something else