Thread: Referencing stringcontrol value
-
October 27th, 2019, 13:37 #1
Referencing stringcontrol value
I know there will be a totally simple way to do this and I'll feel dumb, but anyways:
In a windowclass I have a stringcontrol definition like so:
Code:<stringcontrol name="theology"> <anchored to="knowledgesframe" position="insidetopleft" offset="10,240" /> <center /> <font>sheettextsmall</font> <static>Theology</static> </stringcontrol>
Code:<basicnumber name="theologyscore"> <anchored to="knowledgesframe" position="insidetopright" offset="50,240" width="28" height="16" /> <script> function onDoubleClick(x,y) local abscorevalue = getValue(); local abname = window.theology.getValue(); end </script> </basicnumber>
So, with the control named theologyscore I can also do this if I want to:
Code:local controlname = "theologyscore"; local abscorevalue = window.getDatabaseNode().getChild(controlname).getValue();
local abname = window.theology.getValue();
I would like to reference the stringcontrol named theology with a variable, like I can do it with the theologyscore control in the getChild function in my above example. The problem of course is, that a stringcontrol is not in the database, so I can't do a getDatabaseNode().getChild call on it. So what I would like to do is something like:
Code:local controlname = "theology" local abname = window.GetControlValueByName(controlname)
Is there any way to do something like this?
-
October 27th, 2019, 14:07 #2
Im not quite sure what you are getting at? If stringcontrol is not storing in the database use a stringtype that is?
-
October 27th, 2019, 17:26 #3
Well yeah, I mean instead of stringcontrol I can use stringfield, which is bound to a database node, I just wanted to avoid unneccessarily bloating the db.
The question in general is basically how I can access any xml tag from a lua script? I believe what I would like to accomplish is described here at the section titled Accessing XML parameters from script, but I think I'd need a working example code to be able to wrap my mind around that description.
-
October 27th, 2019, 18:07 #4
Oh, well. As usual, I figure out the solution after I ask for help... :-) So, to answer my own question and maybe enlighten future developers who find this topic years from now:
To access for example a stringcontrol node, that is not in the database, do this (referring to my example codes above):
Instead of
Code:local abname = window.theology.getValue();
Code:local controlname = "theology" local abname = window[controlname].getValue()
So, TLDR move along, no question, figured it out, thanks damned anyway for trying to help. :-)
-
October 28th, 2019, 02:03 #5
Although I am far from 100% sure, I believe I have seen the tag <target> used within some controls to do something similar
-
October 28th, 2019, 14:57 #6
Archangel
- Join Date
- Apr 2008
- Location
- Virginia Beach
- Posts
- 3,096
I believe target only works in cases where target is defined in the control xml. It is not an api feature per se.
-
October 30th, 2019, 06:36 #7
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks