PDA

View Full Version : Referencing stringcontrol value



rpotor
October 27th, 2019, 13:37
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:


<stringcontrol name="theology">
<anchored to="knowledgesframe" position="insidetopleft" offset="10,240" />
<center />
<font>sheettextsmall</font>
<static>Theology</static>
</stringcontrol>


Within the same windowclass I have a number defined like so:



<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>


And this works as is, without problem, but bear with me, we're slowly getting to my question. :-)

So, with the control named theologyscore I can also do this if I want to:


local controlname = "theologyscore";
local abscorevalue = window.getDatabaseNode().getChild(controlname).get Value();


This works because the theologyscore control is in the database. However what I would like to accomplish is that on this line in the code:

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:



local controlname = "theology"
local abname = window.GetControlValueByName(controlname)


Of course I know a GetControlValueByName function does not exist in Fantasy Grounds, well at least as far as I know :-), so it's just to demonstrate what I would like to accomplish.

Is there any way to do something like this?

damned
October 27th, 2019, 14:07
Im not quite sure what you are getting at? If stringcontrol is not storing in the database use a stringtype that is?

rpotor
October 27th, 2019, 17:26
Well yeah, I mean instead of stringcontrol I can use stringfield (https://www.fantasygrounds.com/refdoc/stringfield.xcp), 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 (https://www.fantasygrounds.com/modguide/scripting.xcp) 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.

rpotor
October 27th, 2019, 18:07
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


local abname = window.theology.getValue();


you can do


local controlname = "theology"
local abname = window[controlname].getValue()

This enlightenment came to me on page 11 of the Anatomy of a Ruleset pdf, where it says The globally-visible variables provide shortcuts for other routines to access the character's basic traits (using characteristics.DEX or characteristics["DEX"] notation).

So, TLDR move along, no question, figured it out, thanks damned anyway for trying to help. :-)

Tubel
October 28th, 2019, 02:03
Although I am far from 100% sure, I believe I have seen the tag <target> used within some controls to do something similar

Bidmaron
October 28th, 2019, 14:57
I believe target only works in cases where target is defined in the control xml. It is not an api feature per se.

Tubel
October 30th, 2019, 06:36
I believe target only works in cases where target is defined in the control xml. It is not an api feature per se.

and now I'm 100% sure i didn't know :-)