Thread Tools Display Modes
06-24-15, 07:07 AM   #1
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
XML virtual object

Is it possbile to only create a virtual object if it's does not exists with that global name?
  Reply With Quote
06-24-15, 08:47 AM   #2
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by Resike View Post
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.

Last edited by Mayron : 06-24-15 at 08:58 AM.
  Reply With Quote
06-24-15, 09:15 AM   #3
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Mayron View Post
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.

Last edited by Resike : 06-24-15 at 09:18 AM.
  Reply With Quote
06-24-15, 10:43 AM   #4
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by Resike View Post
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)

Last edited by Mayron : 06-24-15 at 11:42 AM.
  Reply With Quote
06-24-15, 03:00 PM   #5
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Then it's definately stored in another global like table, would be nice to know it's name if it's accessible for lua.
  Reply With Quote
06-24-15, 04:17 PM   #6
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
To my knowledge, the Lua environment doesn't know anything about virtual objects.
  Reply With Quote
06-24-15, 04:27 PM   #7
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Choonstertwo View Post
To my knowledge, the Lua environment doesn't know anything about virtual objects.
How about the XML then?
  Reply With Quote
06-24-15, 05:11 PM   #8
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
Originally Posted by Resike View Post
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").
  Reply With Quote
06-26-15, 09:58 AM   #9
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
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.
__________________
Grab your sword and fight the Horde!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » XML virtual object

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off