Dynamically Adding a checkbox problem

Discussion of Inner Space

Moderators: Lavish Software Team, Moderators

Post Reply
eaglepigjim
Non-Subscriber
Posts: 9
Joined: Thu Apr 05, 2007 9:20 am

Dynamically Adding a checkbox problem

Post by eaglepigjim » Sun May 20, 2007 3:00 pm

I'm having a problem trying to dynamically add a checkbox with a >Net event in the OnLeftClick. If I change it to a simple command it works, but I am writing a .net app with a LavishGUI fortn end, so need to raise the event to .Net.

Code: Select all

UIElement[fraHB0@fraHarvestingBots@Harvesting@tabPigBot@PigBotWindow]&#58;AddChild[CheckBox, HB0_chkSkill2, <CheckBox Name='HB0_chkSkill2' Template='VG.CheckBox'><X>175</X><Y>37</Y><Width>10</Width><Height>10</Height><OnLeftClick>Event[PigBotEvent]&#58;Execute[$&#123;This&#125;, "OnLeftClick"]</OnLeftClick></CheckBox>]
This syntax works for any controls I have in my XML file, it just wont work if I try to dynamically add them. Am I doing something wrong or is there a diferent syntax I could use?

Thanks
J

eaglepigjim
Non-Subscriber
Posts: 9
Joined: Thu Apr 05, 2007 9:20 am

Post by eaglepigjim » Sun May 20, 2007 3:52 pm

I worked around it by creating a template then it worked.

Unchayned
GamingTools Subscriber
Posts: 51
Joined: Sat Oct 09, 2004 9:22 am

Post by Unchayned » Mon May 21, 2007 3:49 am

You have a comma in your nested XML that's not being quoted or escaped, and might be causing the parser to chop up the args to AddChild. Otherwise everything looks in order...I call a ton of these and haven't had an issue. Thanks for the suggestion of using a template though..might cut down on some of those monolithic embedded XML strings I find myself writing.

Unchayned
GamingTools Subscriber
Posts: 51
Joined: Sat Oct 09, 2004 9:22 am

Post by Unchayned » Mon May 21, 2007 3:56 am

On the same note, I'm not sure exactly how you're passing things up to .NET but be sure your lavishdata (${This} in the case posted) isn't being parsed by the command interpreter if you intend it to be part of the final XML. As a rule, when you do anything like this, double-quote the whole string and escape any nested quotes or $s. Also keep in mind that some XML characters require escaping (& goes over to &amp; > goes over to &gt; < goes over to &lt;).

rootkit
GamingTools Subscriber
Posts: 4
Joined: Fri Sep 22, 2006 8:49 am

Post by rootkit » Wed May 23, 2007 4:02 pm

Dont know, how u "try to dynamically add it", but in a C# application I would do it this way:

Code: Select all

string mother = "fraHB0@fraHarvestingBots@Harvesting@tabPigBot@PigBotWindow";
string type = "CheckBox";
string child = "HB0_chkSkill2";
string xml = "add xml stuff here";
LGUIElement element = new LGUIElement&#40;LavishScriptAPI.LavishScript.Objects.GetObject&#40;"UIElement", new string[] &#123; mother &#125;&#41;&#41;;
element.ExecuteMethod&#40;"AddChild", type, child, xml&#41;;
If u are not running this code in the main thread u must frame lock the whole block.

Post Reply