PDA

View Full Version : Which control/object defines ‘source=“...”’ attribute?



Varsuuk
April 12th, 2018, 00:13
Was going through the API page control by control looking for this. Basically, once found was going to see if there was any API call in lua to set/reset this db value. I. was thinking that I had 5 controls that depending on a config switch would represent one of two sets of 5 values.

Didn’t want to use a vague path like .save1, save2, etc.

Am I, as usual, myopic and missed the entry?

Moon Wizard
April 12th, 2018, 04:29
In those cases, it's best to use two controls and show/hide the correct controls based on which config is active. You can't change the source of a control on the fly. For example, that's how extra fields in items are handled in the D&D rulesets.

Another option is to dynamically create/destroy controls, but then you have to track them and lay them out dynamically as well.

Technically, both subwindow and windowlist support source setting, but they are containers not raw data values.

Regards,
JPG

Varsuuk
April 12th, 2018, 14:04
Yup, controlling on page display was my initial thought, just the other approach followed in my head since I didn’t need to change any physicality, just the db source.

Will go the invis/vis route.

Still, I couldn’t find the control in the number/string inheritance chain with the db source tag. Did I miss it or is it left out?


PS: M-O-O-N spells Wizard of FG, thanks for the help.

Moon Wizard
April 12th, 2018, 19:29
Still, I couldn’t find the control in the number/string inheritance chain with the db source tag. Did I miss it or is it left out?


I'm not grokking the question this time.

Some comments that may help.
If a control has a name, it can be referenced from the window script scope by name.
If a control does not have a name and is dynamically created (createControl), then you can store a reference to the control object to reference later.
If a control does not have a name and is statically created (XML), then you can't access.
If you really are just trying to update underlying data in the database, use the DB package API instead.

Regards,
JPG

Varsuuk
April 12th, 2018, 22:17
I'm sorry JPG, I meant something like this:


<!-- AC -->
<number name="armorclass"
source="defenses.ac.total">
<frame name="charsheet_attribute_bonus_frame" offset="7,5,7,5"/>


Again, I might just be oblivious ("might", might be a bit generous, but I'll take it) but I didn't see where this might (I think I am too "mighty" today) appear in the XML and Scripting Reference page.


So the above would be number->numberfield->numbercontrol/databasecontrol ->etc

In none of them did I see any description of a tag or attribute "source". I mean, I know what it is, it creates/references that spot in the xml/db. I had ORIGINALLY asked o then see if there was a "change source" api for it. I get what to do now.

I just wanted to still know where that attribute or tag was described. If only to understand why I didn't find it in case there was another set of data/pages/docs to look at.

I hope you are grokking in fullness now? ;)

Thanks for your patience - I no longer "needed" the info, just want to still know where, in case.

Moon Wizard
April 12th, 2018, 23:10
It's only mentioned in passing here in the descriptive text.
https://www.fantasygrounds.com/refdoc/windowcontrol.xcp

It looks like it has never been fully defined in any documentation that I can find quickly. I guess it's always been used by example.

Regards,
JPG

damned
April 12th, 2018, 23:54
In every possible case where you are using data - access it from the database so you dont need to worry about consistenly using the right path for accessing via the window.
Access via the DB always.
Always give your control a unique name.
Keep the db syntax consistent between npc and pc.

Varsuuk
April 13th, 2018, 02:26
Thanks JPG - it's COOL if it WASN'T mentioned, I just hate looking at not seeing it like I have already done on prior questions. And of course sometimes it is not to be found like anchor=center which you blessed me with!
I had no problem understanding how <tag source="..."> was used - it WAS indeed self-documenting. I asked, as I said before, because I figured whatever component first introduces it would also have (if ANY had it) the method for modifying/reading it if one existed.



In every possible case where you are using data - access it from the database so you dont need to worry about consistenly using the right path for accessing via the window.
Access via the DB always.
Always give your control a unique name.
Keep the db syntax consistent between npc and pc.

I'm only at the UI stage now, though SO close to starting on coding first page at least. Just trying to decide how will setup Saves and Movement controls. Then will see about shrinking the "Ability Modifiers" section - I did it initially like their Character Sheet but it looks too wide for such a limited use datapoint. But it's there and layed out so will wait until complete then revamp look.


Could you maybe show a control or two with the alternate ways of accessing the data? I am not sure what you mean by the "access it from the database so you dont need to worry about consistenly using the right path for accessing via the window." since I haven't yet coded to it.

You need not post actual controls if that would be too much to use as example. You could point to examples of alternate access methods by pointing to the free rulesets, CoreRPG or Savage Worlds or Castles & Crusades or something I can download to look at. Just mention the controls or methods to look at.

damned
April 13th, 2018, 02:34
random code cut from MoreCore



<script>
function onDoubleClick(x, y)
if getValue() > 0 then
local rActor = ActorManager.getActor("pc", window.getDatabaseNode());
Debug.console("rActor: ");
Debug.console(rActor);
local nodeWin = window.getDatabaseNode();
Debug.console("nodeWin: ");
Debug.console(nodeWin);
local sHeroType = nodeWin.getChild("spell_slot_1_name").getValue();
Debug.console("sHeroType: ");
Debug.console(sHeroType);
local msg = {font = "msgfont", icon = "spellicon"};
msg.text = rActor.sName .. " is using a " .. sHeroType;
Comm.deliverChatMessage(msg);
setValue(getValue()-1);
end
return true;
end
</script>


In your case the datasource would be nodeWin.getChild("defenses.ac.total").getValue();

Trenloe
April 13th, 2018, 02:40
Some info on the database with relation to controls here: https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Database#Interface_Interaction

DB API here: https://www.fantasygrounds.com/refdoc/DB.xcp
And Database Node here: https://www.fantasygrounds.com/refdoc/databasenode.xcp

Varsuuk
April 13th, 2018, 07:33
random code cut from MoreCore



<script>
function onDoubleClick(x, y)
if getValue() > 0 then
local rActor = ActorManager.getActor("pc", window.getDatabaseNode());
Debug.console("rActor: ");
Debug.console(rActor);
local nodeWin = window.getDatabaseNode();
Debug.console("nodeWin: ");
Debug.console(nodeWin);
local sHeroType = nodeWin.getChild("spell_slot_1_name").getValue();
Debug.console("sHeroType: ");
Debug.console(sHeroType);
local msg = {font = "msgfont", icon = "spellicon"};
msg.text = rActor.sName .. " is using a " .. sHeroType;
Comm.deliverChatMessage(msg);
setValue(getValue()-1);
end
return true;
end
</script>


In your case the datasource would be nodeWin.getChild("defenses.ac.total").getValue();

Got the gist of what it is doing there, presumably this is a button that causes a cast and the last step updates the remaining spells in the slot.

What would be a similar control/action but where you DIDN'T: "access it from the database so you dont need to worry about consistenly using the right path for accessing via the window." so I can get the contrast. I'm pretty sure I am missing a fine point (or gross one for that matter) here :)

Off to bed, so will see any replies tomorrow.

PS - Thanks Trenloe I had actually! read all of those fully except DB.xcp which I had only skimmed along with couple other packages. I haven't yet been that attentive to those since all my work has been on creating controls and labels thusfar ;)

damned
April 13th, 2018, 07:42
Got the gist of what it is doing there, presumably this is a button that causes a cast and the last step updates the remaining spells in the slot.

What would be a similar control/action but where you DIDN'T: "access it from the database so you dont need to worry about consistenly using the right path for accessing via the window." so I can get the contrast. I'm pretty sure I am missing a fine point (or gross one for that matter) here :)

Off to bed, so will see any replies tomorrow.

PS - Thanks Trenloe I had actually! read all of those fully except DB.xcp which I had only skimmed along with couple other packages. I haven't yet been that attentive to those since all my work has been on creating controls and labels thusfar ;)

I could give you the alternative but I dont want you to use it. So I wont :)
Instead of referencing the db value you reference the same value but do it by its window.control name...

Moon Wizard
April 13th, 2018, 17:35
You'd have to walk up and/or down the window/control parent relationship tree.
https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Scripting#Script_Block_Scope

Cheers,
JPG