Thread Tools Display Modes
10-14-05, 11:31 AM   #61
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
sorry for not replying. I haven't watched this thread in quite some time. I hope you got what you needed from Gello's post. He explained it exactly as it should be. 'this' is a reserved keyword that references the source frame or element that triggered the script function. It will ALWAYS return with whatever called the function.

OOP is a useful thing to learn when making addons. You might consider looking up info on OOP programming on the web, as it could explain a lot of things that we simply can't think of to tell you here. Basically it is a way or organizing your code logically, which makes it easier for you, and anyone else looking at the code afterwards.

Example: (I made this up)

Code:
MyMod = {
	get = {
		unit = function(id) -- gets basic information about specified unit
			if (not id) then id= "player"; end -- error checking
			output = {};
			output.name = UnitName(id);
			output.sex = UnitSex(id);
			output.race = UnitRace(id);
			output.class = UnitClass(id);
			output.level = UnitLevel(id);
			output.rank = UnitPVPRank(id);
			return output;
		end;
	};
	set = {
		config = function() -- creates the config info if it doesn't exist
			if (not MyMod.ConfigOptions) then MyMod.ConfigOptions = {}; end
			if (not MyMod.ConfigOptions.Option1) then MyMod.ConfigOptions.Option1 = "whatever"; end
		end;
	};
};
As shown above, you would be organizing things by what they do. So if you are getting multiple sets of data, you could put it under teh get table. If you are setting variables or what have you, you could put it under the set table. You can organize this any way you want, but the above is a good example of how I do it.

So for example, assuming that MyMod.ConfigOptions is a saved variable:

MyMod.ConfigOptions.PlayerData = MyMod.get.unit("player");


This would store a table in the config options that contains name, sex, race, class, level, and rank for the player using your mod.

Hope this gives you more ideas on what is possible with OOP.

Last edited by Beladona : 10-14-05 at 11:35 AM.
  Reply With Quote
10-14-05, 01:09 PM   #62
shouryuu
A Chromatic Dragonspawn
 
shouryuu's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2005
Posts: 150
I love you! That made sens! And lots of it! WoW! I'm understanding tables and XML! Weeehhhhaaaa!!!!! Thank you so much
  Reply With Quote
10-26-05, 06:47 AM   #63
xmlover
A Fallenroot Satyr
Join Date: Oct 2005
Posts: 25
Originally Posted by Beladona
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;
it's GREAT! a good way to sort the codes sea!

and a few question

1.is that mean I can define function for widget in this way?

for instance. i got a Frame named MyFrame and a button in it call MyButton.
if I want define their OnLoad and OnClick function

can I do it like this?
Code:
MyFrame = {};
MyFrame.OnLoad = function()
               -- codes here
end

MyButton = {};
MyButton.OnClick = function()
              -- codes here
end
but if i wanna refer the MyButton's function like this:
MyFrame.MyButton.OnClick()

how can i do? or is it possible for lua?


2. someone messed their code and i re-make them

at first, i don't know it.through your way, i got it a little and still need your help

Code:
 Oo0o0oOO = {} 
 Oo0o0oOO["QUEST_DETAIL"] = { 
 		OnEvent =
function() Oo0o0oOof() end 
 } 
 Oo0o0oOO["QUEST_PROGRESS"] = { 
 		OnEvent =
function() Oo0o0oOqf() end 
 } 
 Oo0o0oOO["QUEST_COMPLETE"] = { 
 		OnEvent =
function() Oo0o0oOnf() end 
 }
i know that the functions between "Function()" and "end" is what they called

but i was confused by the form....what's the form mean......

i never saw codes like this ......

i know what they try to do is confused me....but i try to catch it and improve my knowledge.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » GUI's

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off