WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   XML virtual object (https://www.wowinterface.com/forums/showthread.php?t=52401)

Resike 06-24-15 07:07 AM

XML virtual object
 
Is it possbile to only create a virtual object if it's does not exists with that global name?

Mayron 06-24-15 08:47 AM

Quote:

Originally Posted by Resike (Post 309346)
Is it possbile to only create a virtual object if it's does not exists with that global name?

If you mean you want a way to check whether a global already exists before creating a virtual object with that name then I don't think that's possible in XML but a global template name for a virtual function is not added to the _G global table I think. So a template's name will not override a global variable name.

Unless you mean you want to create a virtual object with a name that already exists as a global?

If you try to create a new virtual object by reusing a global name of another virtual object then it will not override it, instead the new virtual object you are trying to create will just be ignored. If the global name you are using for this new virtual object is already defined but is not associated to another virtual object then this is fine.

Resike 06-24-15 09:15 AM

Quote:

Originally Posted by Mayron (Post 309350)
If you mean you want a way to check whether a global already exists before creating a virtual object with that name then I don't think that's possible in XML but a global template name for a virtual function is not added to the _G global table I think. So a template's name will not override a global variable name.

Unless you mean you want to create a virtual object with a name that already exists as a global?

If you try to create a new virtual object by reusing a global name of another virtual object then it will not override it, instead the new virtual object you are trying to create will just be ignored. If the global name you are using for this new virtual object is already defined but is not associated to another virtual object then this is fine.

I'm pretty sure it's added the the global table, since you can only reach it with that reference. But i could be wrong.

Mayron 06-24-15 10:43 AM

Quote:

Originally Posted by Resike (Post 309351)
I'm pretty sure it's added the the global table, since you can only reach it with that reference. But i could be wrong.

I don't think virtual object names are stored in there because I did a test:

In the .toc I had 3 files in this order of execution:

test1.lua
test2.xml
test3.lua

test1.lua had this:
Lua Code:
  1. A_GLOBAL_NAME = "hello";
  2. print(A_GLOBAL_NAME)

test2.lua had this:
XML Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/">   
  2.     <Frame name="A_GLOBAL_NAME" inherits="UIPanelDialogTemplate" virtual="true" />
  3. </Ui>

test3.lua had this:
Lua Code:
  1. print(A_GLOBAL_NAME)
  2. local f = CreateFrame("Frame", nil, UIParent, "A_GLOBAL_NAME")
  3. f:SetSize(500, 500)
  4. f:SetPoint("CENTER", UIParent, "CENTER")
  5. f:Show()

And basically test1.lua printed "hello" and so did test3.lua which means A_GLOBAL_NAME was never overwritten but also the frame inheritted from the virtual object named A_GLOBAL_NAME was successfully displayed as well.

EDIT: I also tried altering the XML virtual objects name to "SOME_OTHER_NAME" and in the test3.lua file I did this:

print(_G["SOME_OTHER_NAME"])

which printed nil so no, its definitely not in the _G table :)

It would also explain why CreateFrame's 4th argument "template" for example requires the template/virtual object's name to be a string or a comma-separated string list of names. If you do not supply a string and attempt to use the virtual objects name as a global variable instead then the system cannot find the virtual template because it reads this as a nil value. A global variable name is never created for the virtual/template object which is one reason why its efficient. (at least to my understanding)

(It could however be in some sort of sub-table of the global table which I am unaware of)

Resike 06-24-15 03:00 PM

Then it's definately stored in another global like table, would be nice to know it's name if it's accessible for lua.

Choonstertwo 06-24-15 04:17 PM

To my knowledge, the Lua environment doesn't know anything about virtual objects.

Resike 06-24-15 04:27 PM

Quote:

Originally Posted by Choonstertwo (Post 309376)
To my knowledge, the Lua environment doesn't know anything about virtual objects.

How about the XML then?

Choonstertwo 06-24-15 05:11 PM

Quote:

Originally Posted by Resike (Post 309378)
How about the XML then?

XML doesn't allow any sort of conditional declaration (i.e. you can't say "only declare template X when Y is true").

Lombra 06-26-15 09:58 AM

I think you get an error if you try to create a frame using a non existing template. Could use that maybe. Won't be a pretty solution probably.


All times are GMT -6. The time now is 02:45 AM.

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