Originally Posted by venoabyss
the only thing I have yet to figure out is how to get a pure LUA addon to work. I see no way to call the initial functions to deal with making the primary frame ect.
|
You just make the frame. Any code in the main chunk (eg. not inside a function) will be executed immediately when the Lua file is loaded.
Instead of using an OnLoad script (which can be set, but won't be run for a frame created in Lua) you can either just call the code in the main chunk, or register for the ADDON_LOADED event (which fires with your addon's name as the first argument once your addon's files and saved variables have all been loaded) or the PLAYER_LOGIN event (which fires when all non-load-on-demand addons and saved variables have been loaded, and the loading screen has disappeared) and run your code in response to it.
If your code depends on data contained in saved variables, you should use the event method; otherwise, just put it in the main chunk.
Code:
local frame = CreateFrame("Frame", "MyFrame", UIParent)
frame:SetPoint("CENTER")
frame:SetSize(100, 160)
frame:SetBackdrop(GameTooltip:GetBackdrop()) -- copied because I'm too lazy to type it out
-- This might normally go in an OnLoad script, but you can just put it here:
frame:SetBackdropColor(0, 0, 0, 0.8)
frame:SetBackdropBorderColor(0.8, 0.8, 0.8, 1)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
frame:SetScript("OnHide", frame.StopMovingOrSizing) -- prevents frame sticking to cursor in some situations
-- Or you can register for a loading-related event:
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function(self, event, arg1)
if event == "ADDON_LOADED" then -- realistically you don't need to check, since you're only registered for this one event
if arg1 == "MyAddon" then -- this will be your TOC/folder name
-- your addon's files and saved variables are all loaded
self:SetBackdropColor(0, 0, 0, 0.8)
self:SetBackdropBorderColor(0.8, 0.8, 0.8, 1)
self:RegisterForDrag("LeftButton")
self:SetScript("OnDragStart", frame.StartMoving)
self:SetScript("OnDragStop", frame.StopMovingOrSizing)
self:SetScript("OnHide", frame.StopMovingOrSizing) -- prevents frame sticking to cursor in some situations
end
end
end)