PDA

View Full Version : Accessing other window classes on the same tab



MadBeardMan
January 26th, 2019, 14:56
Greetings All,

This is something I know I've done, just can't remember where or how.

In my tab I have 3 window classes, 'char_abilities', 'char_skills' and 'char_health'

What I'm looking at doing is when rolling a Skill, access the 'char_abilities' window, so I can iterate through them and see if an attribute has been 'checked'.

Can someone help remove the fog from my mind please.

Thanks,
MBM

Andraax
January 26th, 2019, 15:23
Don't go through the windows, just access the DB directly.

Trenloe
January 26th, 2019, 15:25
My recommendation, assuming the data is stored in the database, access the field/s you want in the database. It is better practice to access data in the database rather than the GUI. For a number of reasons - it’s easier to iterate through the data hierarchy, you’re dealing with the "master" data, you don’t have to cater for GUI and DB events, data may not be initialized in the GUI controls across all tabs in the PC sheet until you actually open that tab, the GUI tends to change more often than the DB (especially during development) so you have less code changes to make.

MadBeardMan
January 26th, 2019, 15:25
Don't go through the windows, just access the DB directly.

Thought about that. Button_control is being used which doesn't save in the DB.

Here's the skill list, what I'm looking for is if another skill has been 'checked'.

26120

Cheers

Trenloe
January 26th, 2019, 15:30
Thought about that. Button_control is being used which doesn't save in the DB.
So how does the data persist if you close FG? Or is the button not what you’re wanting to find out if it has been "checked"? In which case the button control not saving in the database is irrelevant - access the fields the "checks" are stored in.

EDIT: Start with window.getDatabaseNode in your button code. https://www.fantasygrounds.com/refdoc/windowinstance.xcp#getDatabaseNode

MadBeardMan
January 26th, 2019, 15:39
So how does the data persist if you close FG? Or is the button not what you’re wanting to find out if it has been "checked"? In which case the button control not saving in the database is irrelevant - access the fields the "checks" are stored in.

EDIT: Start with window.getDatabaseNode in your button code. https://www.fantasygrounds.com/refdoc/windowinstance.xcp#getDatabaseNode

Chap,

The 'button_check' is not stored in the DB at all, I use /save during testing (rather than quitting/closing) and I use getDatabaseNode() for pulling the data (and then going parent etc to move up the DB tree).

This is why I wanted to access the actual GUI.

I've not written the base ruleset, I'm plugging in the scripting etc.

It seems as if '<buttoncontrol>' doesn't save in the DB. If it did, I could iterate through that.

Cheers

MadBeardMan
January 26th, 2019, 15:43
I did, and use nodeWin = window.getDatabaseNode() as I read Hunger dice etc. All works fine.

This is the XML 'saved':


<athletics>
<public />
<name type="string">Athletics</name>
<order type="number">2</order>
<skillrank type="number">2</skillrank>
<skilltext type="formattedtext">
<p></p>
</skilltext>
<specialities type="string">Parkour</specialities>
<specialties type="string">Parkour</specialties>
<type type="string">Physical</type>
</athletics>

No sign of the 'skill_check' that's part of the skill list


<button_attribute name="skill_check" source="skill_check">
<anchored>
<top anchor="top" offset="-1" />
<right parent="name" anchor="left" offset="-16" />
<size width="12" height="12" />
</anchored>
</button_attribute>


So to address these issues, why aren't the buttoncontrols saving in the DB?

Trenloe
January 26th, 2019, 15:44
Chap,

The 'button_check' is not stored in the DB at all, I use /save during testing (rather than quitting/closing) and I use getDatabaseNode() for pulling the data (and then going parent etc to move up the DB tree).
So, I’ll ask again, is this a good feature? I assume you want the state of button_check to be persisted when FG is closed? If so, it needs to be stored in the database. Look at the examples of check buttons in other rulesets to see how they store data in the database.

MadBeardMan
January 26th, 2019, 15:46
So, I’ll ask again, is this a good feature? I assume you want the state of button_check to be persisted when FG is closed? If so, it needs to be stored in the database. Look at the examples of check buttons in other rulesets to see how they store data in the database.

No I don't want them stored, they're a 'one' off, ie you check a skill, roll another skill and it adds the 2 skill levels together. Once the roll is made, all checks are cleared.

Trenloe
January 26th, 2019, 15:53
OK. Thanks for clarifying.

Tabs are usually created as subwindow (https://www.fantasygrounds.com/refdoc/subwindow.xcp) GUI entities. You'll need to navigate the subwindow (https://www.fantasygrounds.com/refdoc/subwindow.xcp) hierarchy. Do a search in a ruleset like 3.5E for .subwindow to see some examples.

Trenloe
January 26th, 2019, 16:07
Additionally, for future reference, if a button template is defined using the buttoncontrol control definition then the button state won't be stored in the database. If buttonfield is used, then the value will be stored as a number data field in the database. I notice the "buttonfield" control is not in the API documentation. It was introduced in v3.0.0 - see info here: https://www.fantasygrounds.com/filelibrary/patchnotes.html (search for "buttonfield").

MadBeardMan
January 26th, 2019, 16:16
Additionally, for future reference, if a button template is defined using the buttoncontrol control definition then the button state won't be stored in the database. If buttonfield is used, then the value will be stored as a number data field in the database. I notice the "buttonfield" control is not in the API documentation. It was introduced in v3.0.0 - see info here: https://www.fantasygrounds.com/filelibrary/patchnotes.html (search for "buttonfield").

When states are stored in the DB, it's easy to 'find' them, plus it's easy to clear them, just requires DB access and of course the performance required to iterate on skill rolls and similar things.

I'm not too worried about performance etc, what I'm after is discovering how to talk to 'data' shown in other windows on a tab.

This ruleset doesn't use subwindow, it's all done inside frames. There must be a way I can access data stored in frames.

Let's try changing the buttoncontrol to a buttonfield, it'll get me moving again on the scripting.

Cheers

MadBeardMan
January 26th, 2019, 16:22
Hi @Trenloe,

Here you go chap. Since changing from 'buttoncontrol' to 'buttonfield' the XML has been updated.


<athletics>
<public />
<name type="string">Athletics</name>
<order type="number">2</order>
<skill_check type="number">1</skill_check>
<skillrank type="number">2</skillrank>
<skilltext type="formattedtext">
<p></p>
</skilltext>
<specialities type="string">Parkour</specialities>
<specialties type="string">Parkour</specialties>
<type type="string">Physical</type>
</athletics>


It'll do for now, allows me to get on with the Dice Pool scripting!

Cheers,
MBM

damned
January 26th, 2019, 23:32
This is definitely the better option.

I know Im late to the party...
And it seems my invitation might have gotten lost in the mail...
And that silence after my arrival will be awkward and all that...

But theres my 2c anyway!

Moon Wizard
January 28th, 2019, 17:27
For future reference, to navigate down the hierarchy with subwindows. If you are within a windowclass script, "<subwindow_controlname>.subwindow"; or if you are in a global script, "<windowinstance>.<subwindow_controlname>.subwindow". Note, if the subwindow has not been instantiated yet (i.e. not active tab), then subwindow will be nil.

Regards,
JPG