Check if control exists
Hi guys,
I'm trying to check whether a (virtual) control exists before I create it. This is the XML Code Code:
<Label name="QuestLabel" virtual="true" font="ZoFontAnnounceMedium" text=""> Lua Code:
Does anyone know why this does not work? Thanks! |
Quote:
TestAddon:CreateQuestLabel(questId, 'QuestLabel1', someControl, yOffset) TestAddon:CreateQuestLabel(questId, 'QuestLabel1', anotherControl, yOffset) So what happens is that the first time, the function creates a child of someControl, and the child has the name QuestLabel1. This is a global name. So now, this label exists. Next, you call the createQuestLabel function again. But for some reason, QuestLabel1 is passed as a labelName again. QuestLabel1 however, is a child of someControl, and not anotherControl. So of course, when you try to get the named child of anotherControl that's named QuestLabel1, it won't exist, because it's not a child of anotherControl. It's a child of someControl. So now label is nil, and it passes the first if statement. But when you try to create a virtual control with the name of QuestLabel1, it already exists, and that's where you get your error. Here's what I'd suggest. Add labelName = containingControl:GetName()..labelName and use that as the label name instead. |
Hi Dolgubon, thanks for your reply!
I checked what you said but the parameter "containingControl" is passed as a hard reference, so it should definitely be the same both times. This is the function I use to call the "CreateQuestLabel" function: Lua Code:
XML-Code: Code:
<GuiXml> type slash command for the first time -> everything workes as intended since the controls don't yet exist type slash command for the 2nd time -> Duplicate error Could this be caused by some weird object instance behaviour? Like that the object "TestAddonGrid" is not the same instance the second time as the first time? |
I believe your problem is because GetNamedChild only returns controls that are prefixed with the parent name. When creating a control you can write "$(parent)<myname>" and it will automatically prefix it with the parent control's name. Then it should work.
But for this kind of problem you should use an ZO_ObjectPool anyways. It takes care of creating and managing your virtual controls. |
ZO_ObjectPool? What is that?
|
I'm shocked you do not know that. :O
Read this: http://wiki.esoui.com/SimpleNotebookTutorial/part7 |
All times are GMT -6. The time now is 08:26 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI