Thread: GUI's
View Single Post
06-04-05, 07:18 PM   #55
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
very nice link... and damnit, stop making me add stuff to my already messy list of bookmarks =p

Functions arranged in tables:

Just a short tutorial that I hope will help you.............
myMod.lua contains:
Code:
myMod = {};
---------------------------------------------
myMod.onLoad = function()
	 this:RegisterEvent("VARIABLES_LOADED");
	 GameTimeFrame:Hide();
end;
myMod.onEvent = function()
	 if (event == "VARIABLES_LOADED") then 
		  -- do whatever here
	 end
	 -- do some more stuff
end;
This should give you an idea of what I meant. Instead of making tons of functions that are global (like MyModOnLoad, MyModOnEvent, etc...) you can just define the global name first, and make all your functions children under that global. Makes more logical sense in my opinion, and it also approaches making Lua act like an Object Oriented Programming Language.

Make sure when you do it this way, that you put a semicolon after the last END for each function (the engine might let you get away with not doing it, but for the sake of proper coding practices, you should do it.). The reason you ahve to put a semicolon there is that each function is essentially just a variable with a function as it's data. It works the same as any normal function, but gets written a little different...

Any Questions? hehe
  Reply With Quote