Hello all,
I'm writing the beginnings of a unit frame addon. Tonight, while writing the boilerplate setup, I encountered something really strange that I can't seem to find an answer to.
My setup is this:
I have a library file that I am loading in advance to define empty globals that other files will then manipulate:
"GeoUnitFrames.lib.lua"
This file looks like this:
Code:
--root GUF object - all method definitions should fall under this global
GUF = {};
--root images folder
GUF.images = "Interface\\Addons\\GeoUnitFrames\\images\\prod\\";
--root Core object
GUF.Core = {};
--root Frames object - all Frames files will create methods under this object
GUF.Frames = {};
GUF.Utils = {};
GUF.Core, GUF.Frames, and GUF.Utils are managed by their own files. My issue is happening when attempting to pass a frame that is created in GUF.Frames:
Code:
--set our identity
self = GUF.Core;
--register our addon message prefix
RegisterAddonMessagePrefix("GEO");
print("Geo Unit Frames load was successful.\n\n");
self.playerFrame = GUF.Frames.Circles:testCircle();
print(self.playerFrame);
GUF.Utils:MakeFrameMovable(self.playerFrame);
function self.ConsoleCommand(cmd)
print("Your command was: " .. cmd);
end
SlashCmdList["GEO"] = self.ConsoleCommand;
SLASH_GEO1 = "/geo";
When self.playerFrame is being created in GUF.Core, from the GUF.Frames.Circles:testCircle(); call, I'm printing the table ID, and then handing the table to GUF.Utils.MakeFrameMovable (to make the frame well, movable). The issue is that the table, once passed, has a different ID inside of the GUF.Utils.MakeFrameMovable call. The function errors when calling SetClampedToScreen on the frame, claiming that the call is nil.
Really scratching my head on this. No idea what's causing the problem. For reference, here is the GUF.Utils file's contents:
Code:
self = GUF.Utils;
self.Classes = {
["Unknown"] = {name = "Unknown", id = 0},
["Warrior"] = {name = "Warrior", id = 1},
["Paladin"] = {name = "Paladin", id = 2};
["Hunter"] = {name = "Hunter", id = 3};
["Rogue"] = {name = "Rogue", id = 4};
["Priest"] = {name = "Priest", id = 5};
["DeathKnight"] = {name = "Death Knight", id = 6};
["Shaman"] = {name = "Shaman", id = 7};
["Mage"] = {name = "Mage", id = 8};
["Warlock"] = {name = "Warlock", id = 9};
["Monk"] = {name = "Monk", id = 10};
["Druid"] = {name = "Druid", id = 11};
};
--colors as defined here http://wowwiki.wikia.com/wiki/Class_colors
self.Classes.Colors = {
-- unknown / no class
[self.Classes["Unknown"].id] = { r = 1, g = 1, b = 1},
--warrior
[self.Classes["Warrior"].id] = { r = 0.78, g = 0.61, b = 0.43},
--paladin
[self.Classes["Paladin"].id] = { r = 0.96, g = 0.55, b = 0.73},
--hunter
[self.Classes["Hunter"].id] = { r = 0.67, g = 0.83, b = 0.45},
--rogue
[self.Classes["Rogue"].id] = { r = 1.00, g = 0.96, b = 0.41},
--priest
[self.Classes["Priest"].id] = { r = 1, g = 1, b = 1},
--deathknight
[self.Classes["DeathKnight"].id] = { r = 0.77, g = 0.12, b = 0.23},
--shaman
[self.Classes["Shaman"].id] = { r = 0.00, g = 0.44, b = 0.87},
--mage
[self.Classes["Mage"].id] = { r = 0.41, g = 0.80, b = 0.94},
--warlock
[self.Classes["Warlock"].id] = { r = 0.58, g = 0.51, b = 0.79},
--monk
[self.Classes["Monk"].id] = { r = 0.33, g = 0.54, b = 0.52},
--druid
[self.Classes["Druid"].id] = { r = 1.00, g = 0.49, b = 0.04}
}
self.MyClass = self.Classes["Unknown"];
unitClassTable = ({UnitClass("player")});
--assign colors to our classes table, assign MyClass
for key, value in pairs(self.Classes) do
value.colors = self.Classes.Colors[value.id];
if(value.id == unitClassTable[3]) then
self.MyClass = value;
end
end
--frame setup
function self.SetAsTargetFrame(unitFrame)
unitFrame:SetFrameRef("TargetFrame", TargetFrame);
end
function self.MakeFrameMovable(frame, button)
print(frame);
local btnString = "LeftButton"; --default, left mouse button
if button then
btnString = button;
end
--don't allow images to go off screen
frame:SetClampedToScreen(true);
frame:SetMovable(true);
frame:EnableMouse(true);
frame:RegisterForDrag(btnString);
frame:SetScript("OnDragStart", function(self)
if IsShiftKeyDown() then
self:StartMoving();
end
end)
frame:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing();
end)
end
Also, here is my TOC file:
Code:
## Title: Geo Unit Frames
## Version: 0.01-a
## Author: John Rubin & DJ Foreman
## Interface: 60200
## SavedVariablesPerCharacter: gufPlayerData
## SavedVariables:
## Notes: Much Unit Frames, Such Geometry, Wow
GeoUnitFrames.lib.lua
Frames\GeoUnitFrames.frames.circles.lua
Utils\GeoUnitFrames.utils.lua
GeoUnitFrames.core.lua
And finally, the actual error:
http://imgur.com/VAGMOyy
Any help would be awesome.
Note, that when I take the MakeFrameMovable call, and move it to GUF.Core, the frame becomes movable, and everything's all peachy-keen. But, I'd like to keep this function call in my Utils file... first world problems.
Thanks for your help dudes, and lady dudes.
Kind Regards,
Mster50