Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

LUA/WOW API

Name: Anonymous 2011-11-10 19:19

/Prog/ I'm learning LUA for wow addon's and it say's to look at samples so I downloaded a very simple addon and looked at the code this was it:

local frame = CreateFrame("FRAME");
frame:RegisterEvent("ADDON_LOADED");
frame:RegisterEvent("DUEL_REQUESTED");

function frame:print(msg)
    DEFAULT_CHAT_FRAME:AddMessage(msg)
end

function frame:OnEvent(event, arg1)
    if event == "ADDON_LOADED" and arg1 == "DuelCancel" then
        if duelcancelbool == nil then
            duelcancelbool = "on";
        end
    elseif event == "DUEL_REQUESTED" then
        if duelcancelbool == "on" then
            CancelDuel();
        end
    end
end

frame:SetScript("OnEvent", frame.OnEvent);
SLASH_DUELCANCEL1 = "/duelcancel";

function SlashCmdList.DUELCANCEL(msg)
    if msg ~= nil then
        msg = string.lower(msg);
    end
    if msg == "on" then
        print("DuelCancel: on");
        duelcancelbool = "on";
    elseif msg == "off" then
        print("DuelCancel: off");
        duelcancelbool = "off";
    else
        if duelcancelbool == "on" then
            print("DuelCancel: ".. duelcancelbool);
        else
            print("DuelCancel: ".. duelcancelbool);
        end
        print("Type /duelcancel off or on to change");       
    end
end

Let me type out what I believe its does.
Assigns a local variable called frame which is equal to CreateFrame("FRAME")
Then it tells the frame variable to register a event when the addon is loaded and also an event when a duel is requested.
Then it creates a function called frame:print(msg) .... ? that tells DEFAULT_CHAT_FRAME to add a message with the msg variable?  and thats where I get confused...

any wow api expert out there willing to help out... kinda a shot in the dark but ill be copying this to a wow forum too

Name: Anonymous 2011-11-11 3:03

duelcancelbool
That's not how dynamic typing is supposed to affect coding style.

By the way, you forgot to use [code] tags.

Don't change these.
Name: Email:
Entire Thread Thread List