WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   a means of checking if a frame exists (https://www.wowinterface.com/forums/showthread.php?t=42499)

Grimsin 01-30-12 09:56 PM

a means of checking if a frame exists
 
is there a means to check if a frame exists not just if it is shown or visible?

if you put an or inside of a setpoint say...
frame:SetPoint("LEFT", otherframe, "LEFT", or "LEFT", someotherframe, "LEFT") would it skip passed the first if it could not find that frame?

Seerah 01-30-12 10:06 PM

frame:SetPoint("LEFT", otherframe or someotherframe, "LEFT")

Grimsin 01-30-12 10:12 PM

Does that work for doing SetParent(something or somethingelse) ? as far as i can tell it does not :(

Seerah 01-30-12 10:42 PM

If, for some reason, it's not working, then do this:

local frame = something or somethingelse
SetParent(frame)

Waky 01-31-12 11:29 AM

I'm pretty sure you can do something along the lines of:

Code:

if frameName then
-- Code to be executed if it exists
end

If I'm not mistaken

If that does nothing you could just to the nil check

Code:

if (frameName~=nil) then
-- Code to be executed if it exists
end


Grimsin 01-31-12 11:31 AM

Quote:

Originally Posted by Waky (Post 251839)
I'm pretty sure you can do something along the lines of:

Code:

if frameName then
-- Code to be executed if it exists
end

If I'm not mistaken

If that does nothing you could just to the nil check

Code:

if (frameName~=nil) then
-- Code to be executed if it exists
end


The first method i know does not work... that only works for addon names. You could do a check to see if an addon is loaded via if name then but does not work for frames that do not exist. Ill try the if framename == nil then do such and such or vice verse ~=

Last night i already went with a method not listed here at all... since what im trying to do is run my UI with files missing and i want to have one file in the UI check to see if frames from the other file are available and run them if they are or dont if they are not. What i ended up doing is just having the file create a variable when it loads and have the other file check for the variable. Most likely not an efficient method and if i can get either of the above to work im going to do that.

Waky 01-31-12 11:41 AM

If you're trying to check if another addon's frames have loaded you need to make sure that those frames are visible (aka not local.) If they're global you can access them via the _G.frameName, I believe.

Torhal 01-31-12 11:44 AM

That does, indeed, work; the frame has to be named, however.

Waky 01-31-12 11:46 AM

Quote:

Originally Posted by Torhal (Post 251842)
That does, indeed, work; the frame has to be named, however.

Another valid point, lol.

Grimsin 01-31-12 11:57 AM

Quote:

Originally Posted by Torhal (Post 251842)
That does, indeed, work; the frame has to be named, however.

What works? doing the "if framename then"? it works if the framename can be found but if the frame does not exist then it fires an error. Im not exactly trying to see if another addon has loaded but rather if a certain file within the same addon has loaded. GrimUI is comprised of like 20 different lua files. In an attempt to find the DC bug in my UI im loading up one file at a time, the problem is many of the files had cross references so im going through and making each file work on its own without any of the cross referencing causing errors. Which is why its pertinent for me to check for frames existence. The best method may in fact be to have each file save a variable and then have other files check for that variable. Problem i foresee with this is any checks for variables have to come after addon loaded and that could cause a problem. It would be much easier if i could just check for a frames existence.

Waky 01-31-12 12:08 PM

If the addon functions are not dependent on learning another frame loading, you can just debug by adding print("frameName has loaded") after a frame is created as a debug method right now. Once you're finished you could remove those.

SDPhantom 01-31-12 12:23 PM

Quote:

Originally Posted by Waky (Post 251841)
If you're trying to check if another addon's frames have loaded you need to make sure that those frames are visible (aka not local.) If they're global you can access them via the _G.frameName, I believe.

Quote:

Originally Posted by Torhal (Post 251842)
That does, indeed, work; the frame has to be named, however.

To make this more simple, no matter how it's assigned, when a frame is created with a name, the Widget API assigns the frame automatically to a global of the same name.

For example, these will create the global MyFrame.
Code:

CreateFrame("Frame","MyFrame",UIParent);--                Creates the frame and API stores it in the global;
local frame=CreateFrame("Frame","MyFrame",UIParent);--        Creates the frame, API stores it in the global, Lua code keeps a local pointer
MyFrame=CreateFrame("Frame","MyFrame",UIParent);--        Redundant, API stores the frame in the global, Lua code overwrites it with itself
MyFrame=CreateFrame("Frame",nil,UIParent);--                Creates a frame with no name, but Lua code stores it in a global anyway (Same result only MyFrame:GetName() will return nil)

These will not:
Code:

CreateFrame("Frame",nil,UIParent);--                        Be careful with this, you create a frame, but have no way of referencing it again
local frame=CreateFrame("Frame",nil,UIParent);--        Creates a frame with no name and only a local pointer is stored


Grimsin 01-31-12 12:50 PM

True story ^

wish the game would come back up im ready to continue hunting this dc bug. With my editor in one hand and the wowi forums in the other i shall slay the mighty bug.

my thinking right now is if i go through and set up each file to function independently with checks in place for any call out of the file so that it does not error, it will make any future issues like this easier to troubleshoot. As of right now i still dont know exactly what file the dcing bug is coming from. Granted im getting closer one file at a time :)

Grimsin 01-31-12 01:17 PM

Should this be at the top of each of my files?

local addonName, addon = ...
_G[addonName] = addon

or just my first file?

Torhal 01-31-12 01:37 PM

The first line should be at the top of any file in which you want to use the shared table and the AddOn's folder name. The second line should only be used once (what's the point of repeatedly putting the AddOn in the global table keyed by name?).

Grimsin 01-31-12 01:45 PM

Quote:

Originally Posted by Seerah (Post 251827)
If, for some reason, it's not working, then do this:

local frame = something or somethingelse
SetParent(frame)

Neither of the or'ing methods work it always trys to hook to the first frame passed and when it finds its not a frame it errors.

doing a frame =~ nil did work :)

Waky 01-31-12 02:28 PM

Quote:

Originally Posted by Grimsin (Post 251860)
Neither of the or'ing methods work it always trys to hook to the first frame passed and when it finds its not a frame it errors.

doing a frame =~ nil did work :)

Did you put ~= or =~?

SDPhantom 01-31-12 02:55 PM

Quote:

Originally Posted by Grimsin (Post 251856)
Should this be at the top of each of my files?

local addonName, addon = ...
_G[addonName] = addon

or just my first file?

I usually have a core file in a UI addon that is loaded first out of all the others that handles all the basic needs, typicly global registration of the addon table, API for registering modules, event callback system, and/or any functions/structures I want globally available to the entire addon.

It doesn't hurt to put that line in all of your files, but it's completely redundant.

Grimsin 01-31-12 02:55 PM

Quote:

Originally Posted by Waky (Post 251862)
Did you put ~= or =~?

~= :) of course

Torhal 01-31-12 04:06 PM

Quote:

Originally Posted by SDPhantom (Post 251863)
I usually have a core file in a UI addon that is loaded first out of all the others that handles all the basic needs, typicly global registration of the addon table, API for registering modules, event callback system, and/or any functions/structures I want globally available to the entire addon.

It doesn't hurt to put that line in all of your files, but it's completely redundant.

Including this line, however, is not redundant:

Code:

local addonName, addon = ...
That ensures the file it's included in has an upvalued version of the name and the shared table. Personally, I prefer NOT putting that table in the global space and instead using it as a shared private namespace.

Grimsin 01-31-12 04:38 PM

Quote:

That ensures the file it's included in has an upvalued version of the name and the shared table. Personally, I prefer NOT putting that table in the global space and instead using it as a shared private namespace.
How do you do that? Originally my goal was to setup a core file that i could put functions in that would be later used in other files as well as setup a handful of things.

Also i have my options and settings setup for LOD thanks to Vrul so i needed functions in my files to not only work within the addon but as well as with the LOD options files. If its made a private name space will the LOD config still be able to pull the functions?

This is currently what my core looks like...
Code:

local addonName, addon = ...
_G[addonName] = addon

--[[-----------------------------------------------------------------------------
Event handling - Use one frame to process multiple individual OnEvent needs
-------------------------------------------------------------------------------]]
do
        local frame, select, next, events = CreateFrame('Frame'), select, pairs({ })
        --local frame, select, next, events = CreateFrame('Frame'), select, next, {} -- maybe a fix? but no...
        local register, unregister = frame.RegisterEvent, frame.UnregisterEvent
        frame:Hide()

        frame:SetScript('OnEvent', function(self, event, ...)
                for reference, func in next, events[event], nil do
                        func(reference, event, ...)
                end
        end)

        function addon.RegisterEvent(reference, event, func)
                if not events[event] then
                        events[event] = { }
                        register(frame, event)
                end
                events[event][reference] = func
        end

        function addon.RegisterEvents(reference, func, ...)
                local event
                for index = 1, select('#', ...) do
                        event = select(index, ...)
                        if not events[event] then
                                events[event] = { }
                                register(frame, event)
                        end
                        events[event][reference] = func
                end
        end

        function addon.UnregisterEvent(reference, event)
                if events[event] then
                        events[event][reference] = nil
                        if not next(events[event]) then
                                events[event] = nil
                                unregister(frame, event)
                        end
                end
        end

        function addon.UnregisterAllEvents(reference)
                for event, registry in next, events, nil do
                        registry[reference] = nil
                        if not next(registry) then
                                events[event] = nil
                                unregister(frame, event)
                        end
                end
        end
end

--[[-----------------------------------------------------------------------------
SafeCall - Queue a method of addon to run once combat ends if needed
-------------------------------------------------------------------------------]]
do
        local combatLockdown, queue = InCombatLockdown(), { }

        addon.RegisterEvent("Core-SafeCall-EnterCombat", 'PLAYER_REGEN_DISABLED', function(self)
                combatLockdown = true
        end)

        addon.RegisterEvent("Core-SafeCall-LeaveCombat", 'PLAYER_REGEN_ENABLED', function(self)
                combatLockdown = nil
                for method, arg in pairs(queue) do
                        addon[method](addon, arg)
                        queue[method] = nil
                end
        end)

        function addon:SafeCall(method, arg)
                if combatLockdown then
                        queue[method] = arg or false
                else
                        addon[method](addon, arg)
                end
        end
end

--[[-----------------------------------------------------------------------------
Localized class name to file class name look up table
-------------------------------------------------------------------------------]]
local CLASS = { }
for fileName, localName in pairs(LOCALIZED_CLASS_NAMES_MALE) do
        CLASS[localName] = fileName
end
for fileName, localName in pairs(LOCALIZED_CLASS_NAMES_FEMALE) do
        CLASS[localName] = fileName
end
addon.CLASS = CLASS

--[[-----------------------------------------------------------------------------
MoneyToString - Get formatted text from an ammount of copper
-------------------------------------------------------------------------------]]
function addon:MoneyToString(ammount, forceIcons)
        if type(ammount) ~= 'number' then
                ammount = 0
        end
        local cu = ammount % 100
        ammount = floor(ammount / 100)
        local ag, au = ammount % 100, floor(ammount / 100)
        local cuInd, agInd, auInd
        if GetCVarBool('showChatIcons') or forceIcons then
                cuInd = [[|TInterface\MoneyFrame\UI-CopperIcon:0|t]]
                agInd = [[|TInterface\MoneyFrame\UI-SilverIcon:0|t ]]
                auInd = [[|TInterface\MoneyFrame\UI-GoldIcon:0|t ]]
        else
                cuInd = "|cffeda55fc|r"
                agInd = "|cffc7c7cfs|r "
                auInd = "|cffffd700g|r "
        end
        local string = ""
        if au > 0 then
                string = au .. auInd .. ag .. agInd
        elseif ag > 0 then
                string = ag .. agInd
        end
        return string .. cu .. cuInd
end

--[[-----------------------------------------------------------------------------
DoNothing - A simple dummie/do nothing function
-------------------------------------------------------------------------------]]
local function DoNothing()
end
addon.DoNothing = DoNothing

--[[-----------------------------------------------------------------------------
SetUIScale - Set UI Scale to its smallest size.
-------------------------------------------------------------------------------]]
function addon:SetUIScale()
        SetCVar("useUiScale", 1)
        SetCVar( "uiScale", 0.63999998569489);
end

--[[-----------------------------------------------------------------------------
HideTooltip - Hide GameTooltip (several frames use this)
-------------------------------------------------------------------------------]]
function addon:HideTooltip()
        GameTooltip:Hide()
        self.tooltip = nil
end

--[[-----------------------------------------------------------------------------
HideFrame - Hide a frame, prevents it from being reshown
-------------------------------------------------------------------------------]]
function addon:HideFrame(reference)
        local frame = type(reference) == 'string' and _G[reference] or reference
        if type(frame) ~= 'table' then return end
        frame.Show = DoNothing
        frame:Hide()
end

--[[-----------------------------------------------------------------------------
ShowFrame - Show a frame, undoing :HideFrame behavior
-------------------------------------------------------------------------------]]
function addon:ShowFrame(reference)
        local frame = type(reference) == 'string' and _G[reference] or reference
        if type(frame) ~= 'table' then return end
        frame.Show = nil
        frame:Show()
end

--[[-----------------------------------------------------------------------------
LockFrame - Lock a frame, prevents SetPoint and ClearAllPoints from working
-------------------------------------------------------------------------------]]
function addon:LockFrame(reference)
        local frame = type(reference) == 'string' and _G[reference] or reference
        if type(frame) ~= 'table' then return end
        frame.SetPoint = DoNothing
        frame.ClearAllPoints = DoNothing
end

--[[-----------------------------------------------------------------------------
UnlockFrame - Undo :LockFrame
-------------------------------------------------------------------------------]]
function addon:UnlockFrame(reference)
        local frame = type(reference) == 'string' and _G[reference] or reference
        if type(frame) ~= 'table' then return end
        frame.SetPoint = nil
        frame.ClearAllPoints = nil
end

--[[-----------------------------------------------------------------------------
RunSlashCmd - This no longer functions correctly as of patch 4.3
-------------------------------------------------------------------------------]]
local _G = _G
function addon:RunSlashCmd(cmd)
  local slash, rest = cmd:match("^(%S+)%s*(.-)$")
  for name, func in pairs(SlashCmdList) do
    local i, slashCmd = 1
    repeat
        slashCmd, i = _G["SLASH_"..name..i], i + 1
        if slashCmd == slash then
          return true, func(rest)
        end
    until not slashCmd
  end
  -- Okay, so it's not a slash command. It may also be an emote.
  local i = 1
  while _G["EMOTE" .. i .. "_TOKEN"] do
    local j, cn = 2, _G["EMOTE" .. i .. "_CMD1"]
    while cn do
        if cn == slash then
          return true, DoEmote(_G["EMOTE" .. i .. "_TOKEN"], rest);
        end
        j, cn = j+1, _G["EMOTE" .. i .. "_CMD" .. j]
    end
    i = i + 1
  end
end

--[[-----------------------------------------------------------------------------
GetSlashFunc - returns a slash command function on success or an informative error function on failure.
-------------------------------------------------------------------------------]]
function addon:GetSlashFunc(cmd)
        if not cmd then
                return function(cmd) print("You must supply a command.") end
        end
        if cmd:sub(1, 1) ~= "/" then
                cmd = "/" .. cmd
        end
        for id, val in pairs(_G) do
                if id:sub(1, 5) == "SLASH" and val == cmd then
                        local slashID = id:match("SLASH_(%a*)%d*")
                        return SlashCmdList[slashID]
                end
        end
        -- Didn't find one?
        return function(cmd) print(cmd, "doesn't exist.") end
end

--[[-----------------------------------------------------------------------------
Decimal Truncate Function
-------------------------------------------------------------------------------]]
function addon:truncate(number, decimals)
    return number - (number % (0.1 ^ decimals))
end

--[[-----------------------------------------------------------------------------
Class/Reaction type Coloring
-------------------------------------------------------------------------------]]
do
        local format = string.format
        GCHex = function(color)
                return format('|cff%02x%02x%02x', color.r * 255, color.g * 255, color.b * 255)
        end
end
function addon:unitColor(unit)
        local color = { r=1, g=1, b=1 }
        if UnitIsPlayer(unit) then
                local _, class = UnitClass(unit)
                color = RAID_CLASS_COLORS[class]
                return color
        else
                local reaction = UnitReaction(unit, "player")
                if reaction then
                        color = FACTION_BAR_COLORS[reaction]
                        return color
                end
        end
        return color
end

--[[-----------------------------------------------------------------------------
Durability % Coloring
-------------------------------------------------------------------------------]]
local tmpString = ""
function addon:DurColor(percent)
        if percent >= 80 then
                tmpString = "|cff00FF00"
        elseif percent >= 60 then
                tmpString = "|cff99FF00"
        elseif percent >= 40 then
                tmpString = "|cffFFFF00"
        elseif percent >= 20 then
                tmpString = "|cffFF9900"
        elseif percent >= 0 then
                tmpString = "|cffFF2000"
        end
        return tmpString;
end

--[[-----------------------------------------------------------------------------
Delay a function
-------------------------------------------------------------------------------]]
local waitTable = {};
local waitFrame = nil;
function addon:FuncDelay(delay, func, ...)
  if(type(delay)~="number" or type(func)~="function") then
    return false;
  end
  if(waitFrame == nil) then
    waitFrame = CreateFrame("Frame","WaitFrame", UIParent);
    waitFrame:SetScript("onUpdate",function (self,elapse)
      local count = #waitTable;
      local i = 1;
      while(i<=count) do
        local waitRecord = tremove(waitTable,i);
        local d = tremove(waitRecord,1);
        local f = tremove(waitRecord,1);
        local p = tremove(waitRecord,1);
        if(d>elapse) then
          tinsert(waitTable,i,{d-elapse,f,p});
          i = i + 1;
        else
          count = count - 1;
          f(unpack(p));
        end
      end
    end);
  end
  tinsert(waitTable,{delay,func,{...}});
  return true;
end

--[[-----------------------------------------------------------------------------
Blizzard Build comparisonn for ptr/beta/live compatible versions
-------------------------------------------------------------------------------]]
function addon:CompareBuild(comver, combuild, comref, lowcomref, highcomref)
        local version, build, bdate, toc = GetBuildInfo()
        if version > comver and build > combuild then
                addon[highcomref]()
        elseif version < comver and build < combuild then
                addon[lowcomref]()
        elseif version == comver and build == combuild then
                addon[comref]()
        end
end

--[[-----------------------------------------------------------------------------
Reload Frame
-------------------------------------------------------------------------------]]
function addon:OpenReloadFrame(myfunc)
        local reloadFrame
        if(reloadFrame) then
                return reloadFrame:Show()
        end

        reloadFrame = CreateFrame("Frame", nil, UIParent)
        reloadFrame:SetHeight(160)
        reloadFrame:SetWidth(350)
        reloadFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 200)
        reloadFrame:SetBackdrop{
                bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
                edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
                tile = true,
                tileSize = 32,
                edgeSize = 32,
                insets = {
                        left = 11,
                        right = 12,
                        top = 12,
                        bottom = 11
                }
        }

        local text = reloadFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalHuge")
        text:SetText("GrimUI: Reload")
        text:SetPoint("TOP", 0, -20)

        local text2 = reloadFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
        text2:SetText("GrimUI requires a reload\n to finish its configuration.")
        text2:SetPoint("TOP", 0, -60)

        local button1 = CreateFrame("Button", "okay", reloadFrame, "UIPanelButtonTemplate")
        button1:SetHeight(45)
        button1:SetWidth(125)
        button1:SetPoint("BOTTOMLEFT", 15, 15)
        button1:SetText("Reload")
        button1:RegisterForClicks("AnyUp")
        button1:SetScript("OnClick", myfunc)

        local button2 = CreateFrame("Button", "cancel", reloadFrame, "UIPanelButtonTemplate")
        button2:SetHeight(45)
        button2:SetWidth(125)
        button2:SetPoint("BOTTOMRIGHT", -15, 15)
        button2:SetText("Cancel")
        button2:RegisterForClicks("AnyUp")
        button2:SetScript("OnClick", function() reloadFrame:Hide() end)
end

--[[-----------------------------------------------------------------------------
LibSharedMedia support
-------------------------------------------------------------------------------]]
local LSM = LibStub('LibSharedMedia-3.0')
LSM:Register('background', addonName, [[Interface\Addons\]] .. addonName .. [[\Media\MainBG]])
LSM:Register('font', "Franklin Gothing Medium", [[Interface\Addons\]] .. addonName .. [[\Media\Font1.ttf]])
LSM:Register('font', "Comic Sans MS", [[Interface\Addons\]] .. addonName .. [[\Media\Font3.ttf]])

--[[-----------------------------------------------------------------------------
Localization support. AceLocale
-------------------------------------------------------------------------------]]
local AceLocale = LibStub("AceLocale-3.0")
local L = AceLocale:GetLocale( "GrimUI", true )


Seerah 01-31-12 05:24 PM

Quote:

Originally Posted by Grimsin (Post 251860)
Neither of the or'ing methods work it always trys to hook to the first frame passed and when it finds its not a frame it errors.

doing a frame =~ nil did work :)

Then you asked the wrong question. You asked if a frame had been created yet. If a frame has not been created, then it is nil - assuming that you used a unique name or unique global variable for it. If it is nil, then my line will pass through the or. If, as you say, it throws an error saying that it's not a table, then it's not nil. It's equal to something else. Meaning that you are using the same variable name for multiple things.

Grimsin 01-31-12 06:03 PM

Quote:

Originally Posted by Seerah (Post 251875)
Then you asked the wrong question. You asked if a frame had been created yet. If a frame has not been created, then it is nil - assuming that you used a unique name or unique global variable for it. If it is nil, then my line will pass through the or. If, as you say, it throws an error saying that it's not a table, then it's not nil. It's equal to something else. Meaning that you are using the same variable name for multiple things.

I dont mean that it finds that its not a frame it tells me that it just does not find it at all period and then it stops the code and shoots an error... ill try it again when i get a chance... the frame ~= nil seems to be working fine

Code:

function addon:ArtSetPoint()
        skin:SetPoint('BOTTOMLEFT', -addon.settings.artSetPoint, 0)
        skin:SetPoint('BOTTOMRIGHT', addon.settings.artSetPoint, 0)
       
        -- The following is done so TargetFrame.lua does not need to load first or at all.
        if GrimUITargetFrame ~= nil then
                skin[4]:SetParent("GrimUITargetFrame")
                skin[4]:SetPoint('BOTTOM', GrimUITargetFrame, 'BOTTOM', 0, 4)
        end
end


Torhal 01-31-12 07:17 PM

Quote:

Originally Posted by Grimsin (Post 251873)
How do you do that? Originally my goal was to setup a core file that i could put functions in that would be later used in other files as well as setup a handful of things.

I have my AddOn "core" table, which can be exposed to the world via the global table. Then I use the AddOn-wide table provided by "..." as a private namespace for things I'd rather keep internal but will still be accessible by every file in the AddOn.

SDPhantom 01-31-12 07:38 PM

Quote:

Originally Posted by Torhal (Post 251868)
Including this line, however, is not redundant

The code as posted in its intent, to register the shared table as a global, would be redundant. Reregistering a global multiple times follows the exact definition of redundancy.



Torhol's method of having an addon remain out of the global namespace is a valid approach, although if you have modules loaded as LoD, there isn't any other way around it. Also a global namespace helps with poking around your addon while trying to debug errors.

Grimsin 01-31-12 10:02 PM

Okay i double checked the "or" business and yea you CAN NOT pass a non existent frame through the or statement the way you had suggested. It gives an error that says region unknown and stops. It will not just skip over.

Also... I FOUND THE DC BUG!!! well... what file its in anyhow... i posted relevant code in the other post about it...

Torhal 01-31-12 10:03 PM

Quote:

Originally Posted by SDPhantom (Post 251886)
The code as posted in its intent, to register the shared table as a global, would be redundant. Reregistering a global multiple times follows the exact definition of redundancy.

Aye - already said as much. :)

Phanx 02-01-12 05:46 PM

Quote:

Originally Posted by Grimsin (Post 251895)
Okay i double checked the "or" business and yea you CAN NOT pass a non existent frame through the or statement the way you had suggested. It gives an error that says region unknown and stops. It will not just skip over.

I don't know what you're doing, but:

Code:

frame:SetPoint("BOTTOM", otherFrame or UIParent, "CENTER", 0, 100)
has always worked for me, and is actively used in several of my published addons.

If you're seeing an error, in order to tell you why, we need to see both your actual code, and the actual error.

Grimsin 02-01-12 08:32 PM

Quote:

Originally Posted by Phanx (Post 251929)
I don't know what you're doing, but:

Code:

frame:SetPoint("BOTTOM", otherFrame or UIParent, "CENTER", 0, 100)
has always worked for me, and is actively used in several of my published addons.

If you're seeing an error, in order to tell you why, we need to see both your actual code, and the actual error.

On a frame that does not actually exist?

Seerah 02-01-12 08:37 PM

I've done the or assignment in the past, too, which is why I said "if, for some reason, this is not working for you then..." Yes, on a frame that doesn't exist. The only way it would move to UIParent (in Phanx's example) is if otherFrame was nil.

We can only help you with an error if we see what the error actually was and the code that triggered it.


/edit: you said that the error mentioned that it wasn't a table. Frames are just special tables. A nil value would have given you a nil error. As I mentioned above, you must be assigning something else to that variable name that isn't a table/frame.

Grimsin 02-02-12 12:46 AM

Quote:

Originally Posted by Seerah (Post 251944)
I've done the or assignment in the past, too, which is why I said "if, for some reason, this is not working for you then..." Yes, on a frame that doesn't exist. The only way it would move to UIParent (in Phanx's example) is if otherFrame was nil.

We can only help you with an error if we see what the error actually was and the code that triggered it.


/edit: you said that the error mentioned that it wasn't a table. Frames are just special tables. A nil value would have given you a nil error. As I mentioned above, you must be assigning something else to that variable name that isn't a table/frame.

It did not say that it was an invalid table it said invalid region

Phanx 02-03-12 03:33 AM

Quote:

Originally Posted by Grimsin (Post 251942)
On a frame that does not actually exist?

Yes. Just now, I typed:

Code:

/dump LOLframe
Verification that no such frame existed was printed to my chat frame:

Quote:

Dump: LOLframe
LOLframe = nil,
empty result
Then, I typed:

Code:

/run ShieldsUp:ClearAllPoints() ShieldsUp:SetPoint("CENTER", LOLframe or UIParent, "CENTER", 0, 0)
The ShieldsUp frame was correctly moved to the center of the UIParent frame, since there is no such thing as a LOLframe frame.

Then, to try to replicate your error, I typed:

Code:

/run LOLframe = "haha"
Then, I again typed:

Code:

/run ShieldsUp:ClearAllPoints() ShieldsUp:SetPoint("CENTER", LOLframe or UIParent, "CENTER", 0, 0)
This error occurred:

Quote:

1x <string>:"ShieldsUp:ClearAllPoints() ShieldsUp:SetPoi...":1: <unnamed>:SetPoint(): Couldn"t find region named "haha"
... which sounds very similar to the error you're getting (but for some reason refuse to actually post, despite the fact that this thread would have been over at reply #1 if you had just posted it), which means that Seerah's hunch is correct, and you are trying to position your frame relative to something other than another frame (or frame region, since you can position frames relative to font strings and textures, as well as actual frames).

Most likely, you used the same generic name for both a frame and something else in your code, which is why I always criticize people for using generic names in the code they post. If you use descriptive names, and follow basic naming conventions, you will never have this problem.

Grimsin 02-03-12 02:11 PM

I didnt post the error because it was trivial because doing the nonexistantframe ~= nil worked fine and thinking about it if that is working it says that the frame does = nil so why would it work one way and not the other?? It may be that it works for the setpoint and not the setparent or something. But i didnt post the error because i moved over the issue it was trivial to my goal at the time which was tracking down the dc bug... theres plenty of other issues in the code :) im working on naming everything more specifically as we type. There are issues now with the saved variable functions and im getting tons of errors claiming it cant find my variables so who knows what happened. One thing at a time...

SDPhantom 02-03-12 02:59 PM

frame:SetPoint() has some quirks about the frame argument, if it's a string, it references by the frame by name. If it's a table (the reference of the UI object is stored as a userdata in index zero), it tries to use it as the frame directly. If it's nil, it references the screen itself.

Seerah 02-03-12 03:32 PM

Quote:

nonexistantframe ~= nil worked fine and thinking about it if that is working it says that the frame does = nil
No, that says that the frame does not = nil ;)

Grimsin 02-04-12 10:25 AM

Quote:

Originally Posted by Seerah (Post 252051)
No, that says that the frame does not = nil ;)

Yes but in the fashion i have used it... if it works both ways it means it fires right when it does not = nil and fires right when it does = nil. meaning it is nil when i need it to be lol. :) Like i said it may have just been the setparent that had issues with the or statement. i didnt spend that much time on it.

Seerah 02-04-12 01:29 PM

What I meant was that if your variable was assigned but not to a frame, ~=nil would still evaluate to true.


All times are GMT -6. The time now is 05:35 PM.

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