WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   GUI's (https://www.wowinterface.com/forums/showthread.php?t=703)

Beladona 10-14-05 11:31 AM

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.

shouryuu 10-14-05 01:09 PM

I love you! That made sens! And lots of it! WoW! I'm understanding tables and XML! Weeehhhhaaaa!!!!! Thank you so much :D

xmlover 10-26-05 06:47 AM

Quote:

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. :p


All times are GMT -6. The time now is 09:03 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI