PDA

View Full Version : Second column in windowlist not responsive; how to reference a field in two places?



cscase
August 2nd, 2013, 15:04
Hey all,
I've been gradually progressing on my first ruleset modding project, and learning a lot in the process. I have a couple more questions I would like to ask you about.

1. Numberfields in wrapped columns not taking input - I set up a windowclass that has a label and then two numberfields, and I have a windowlist of these items. I let my windowlist wrap and make second and third columns of these entries, and got it looking great. But then I noticed that in the second and third columns, I can't edit the numberfields. I can't make keyboard input into them, nor can I edit them using the scroll wheel. In the first column, though, I can do those things just fine.

2. How to have a data field appear in multiple places? - I would like to have one of the aforementioned numberfields' values show up in a separate place on the character sheet, and make it editable from either place. That is, if I change it in one place, it changes in both places. How can I create a numberfield elsewhere on the sheet and tell FG that I want it to use the value from that particular skill field?

Thanks all!

Trenloe
August 2nd, 2013, 15:14
1. Numberfields in wrapped columns not taking input - I set up a windowclass that has a label and then two numberfields, and I have a windowlist of these items. I let my windowlist wrap and make second and third columns of these entries, and got it looking great. But then I noticed that in the second and third columns, I can't edit the numberfields. I can't make keyboard input into them, nor can I edit them using the scroll wheel. In the first column, though, I can do those things just fine.
Not sure without seeing the code you're using.


2. How to have a data field appear in multiple places? - I would like to have one of the aforementioned numberfields' values show up in a separate place on the character sheet, and make it editable from either place. That is, if I change it in one place, it changes in both places. How can I create a numberfield elsewhere on the sheet and tell FG that I want it to use the value from that particular skill field?
The best way to do this is tie the controls to the same underlying database field. There are plenty of examples of this in the 3.5e or 4e rulesets. For example, in 3.5e the "Reflex" save is shown on different pages of the character sheet, with the same source: source="saves.reflex.total" Have a look in the 3.5e files \charsheet\charsheet_main.xml and \charsheet\charsheet_combat.xml and search for "reflex" to see the 2 controls with the same source. As they are defined with the same source, if the underlying database entry is changed then all controls tied to this source should update with the change.

cscase
August 3rd, 2013, 07:45
Thanks once again, Trenloe.

I figured out the deal with the columns not all taking input. Somehow I had the width set way wider in my windowclass definition than the column width in my windowlist.

I guess my understanding of scope and the syntax of referencing things in different places in a ruleset is mostly non-existent. I'm looking at the example you mentioned, reflex, and I see that there are clear tags down the "path" you mention, in the db.xml: saves.reflex.total. In the skills I'm working with, it seems like that's not really the case. I wonder if maybe somewhere I'm not providing a name for something, or some explicit direction for setting up the db. Here's what I have in my db. Let's take the first skill for example - Fleeing.

<skills idcounter="25">
<holder name="test" owner="true" />
<id-00001>
<holder name="test" owner="true" />
<label type="string">Fleeing</label>
<pool type="number">0</pool>
<rating type="number">6</rating>

It looks like I would say skills.id-00001.pool. I tested that and it works, but ... is this id-00001 tag safe to reference? I'm wondering if that might not always be the same on everybody's db, if it's being dynamically generated. What I'm getting at is, maybe at some point, things might get shuffled around and some other skill might be id-00001, not fleeing. Is that possible/likely? Do I need to write a piece of script to give the skill (fleeing in this example) a proper name instead of id-00001? Or maybe a for loop to give ALL of the skills proper names in the db? Or does it not matter and I will be okay using the id-xxxxx nomer? I apologize if this seems like a silly question. Thanks!

Trenloe
August 3rd, 2013, 13:54
It looks like I would say skills.id-00001.pool. I tested that and it works, but ... is this id-00001 tag safe to reference? I'm wondering if that might not always be the same on everybody's db, if it's being dynamically generated. What I'm getting at is, maybe at some point, things might get shuffled around and some other skill might be id-00001, not fleeing. Is that possible/likely? Do I need to write a piece of script to give the skill (fleeing in this example) a proper name instead of id-00001? Or maybe a for loop to give ALL of the skills proper names in the db? Or does it not matter and I will be okay using the id-xxxxx nomer? I apologize if this seems like a silly question. Thanks!
That's a very good question. The answer to which is "it depends"... :-)

If you're dynamically generating these controls/records and you are *always* generating them in the same order, then you could use the id-XXXXX name. However, as you point out, there could be a possibility of this not being the case in certain situations. Plus, if you decide to add in one more skill, then you might have to change all of your code to take into account the new reference names.

It's good programming to use names relating to the entity in question, "Fleeing" in your example.

Looking at the 3.5e ruleset, the skills entry is dynamically created, based off the following control (which is anchored to the ".skilllist" datasource in the DB):

<windowlist name="skilllist">
<anchored>
<to>skillframe</to>
<position>over</position>
<offset>-10,-12</offset>
<top>
<offset>26</offset>
</top>
</anchored>
<datasource>.skilllist</datasource>
<class>charsheet_skilllistitem</class>
<sortby>
<control>label</control>
<control>sublabel</control>
</sortby>
<script file="charsheet/scripts/charsheet_skilllist.lua" />
</windowlist>
The constructDefaultSkills() function is called as part of the onInit function (which runs when the control is initialised) in charsheet/scripts/charsheet_skilllist.lua

-- Create default skill selection
function constructDefaultSkills()
bInit = false;

local aSystemSkills = GameSystemManager.getSkillList();

...
<more code to set the values here>

The "GameSystemManager.getSkillList();" command gets the skill list from the \scripts\data_common.lua script, which contains the whole list of skills used. For example, the Pathfinder skill data:

PF_skilldata = {
["Acrobatics"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Appraise"] = {
stat = "intelligence"
},
["Bluff"] = {
stat = "charisma"
},
["Climb"] = {
stat = "strength",
armorcheckmultiplier = 1
},
["Craft"] = {
sublabeling = true,
stat = "intelligence"
},
["Diplomacy"] = {
stat = "charisma"
},
["Disable Device"] = {
stat = "dexterity",
armorcheckmultiplier = 1,
trainedonly = 1
},
["Disguise"] = {
stat = "charisma"
},
["Escape Artist"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Fly"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Handle Animal"] = {
stat = "charisma",
trainedonly = 1
},
["Heal"] = {
stat = "wisdom"
},
["Intimidate"] = {
stat = "charisma"
},
["Knowledge"] = {
sublabeling = true,
stat = "intelligence",
trainedonly = 1
},
["Linguistics"] = {
stat = "intelligence",
trainedonly = 1
},
["Perception"] = {
stat = "wisdom"
},
["Perform"] = {
sublabeling = true,
stat = "charisma",
trainedonly = 1
},
["Profession"] = {
sublabeling = true,
stat = "wisdom",
trainedonly = 1
},
["Ride"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Sense Motive"] = {
stat = "wisdom"
},
["Sleight of Hand"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Spellcraft"] = {
stat = "intelligence",
trainedonly = 1
},
["Stealth"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Survival"] = {
stat = "wisdom"
},
["Swim"] = {
stat = "strength",
armorcheckmultiplier = 1
},
["Use Magic Device"] = {
stat = "charisma",
trainedonly = 1
}
}

Then the constructDefaultSkills function continues and constructs the needed skills dynamically in the "for k,t in pairs(aSystemSkills) do" loop.

Hope this helps. The 3.5e ruleset is a little nested (i.e. you need to look through a few scripts/XML files to see the whole picture) so can be a bit confusing at first. Your editor "find in files" command is your friend here! :-)

cscase
August 4th, 2013, 01:34
Thank you, Trenloe! This makes sense and I think you got me moving in the right direction, with some bits of info that I needed.

I first tried creating a new campaign with this same ruleset, which referenced the skill by the <id-xxx> notation, and as we suspected might happen, the id numbers came out differently in the db.xml and it just didn't work right.

I really struggled with tracing through the 3.5e code and being able to tell what parts are actually relevant, because there is just so much going on in that ruleset that I don't understand. So many moving parts, so to speak. I learned some things looking at it, but eventually I gave up trying to figure out what part I needed to steal.

I think I found a way that ~almost~ seems to work. I'm still working on it and I'm not sure if ultimately this is a good route to go, but here's what I did:

In the script that creates new windows in the windowlist, it does this (and this is very similar in 3.5e):

-- Set properties and create missing entries for all known skills
for k, t in pairs(skilldata) do
local matches = winlist[k];

if not matches then
local newwin = createWindow();
newwin.label.setValue(k);
newwin.pool.setValue(0);
matches = { newwin };
end
end

Well, I noticed that createWindow can take a parameter telling what db node you want the resulting window on, so, after tinkering a bit, I ending up providing a parameter for the createWindow above, like this:

local newwin = createWindow("."..k);

This results in my db looking like this:


<root version="2.9" release="1">
<charsheet>
<id-00001>
<hp type="number">0</hp>
<languages type="string">English</languages>
<name type="string">John Doe</name>
<occupation type="string">Musician</occupation>
<skills>
<Athletics>
<label type="string">Athletics</label>
<pool type="number">2</pool>
<rating type="number">5</rating>
</Athletics>
...etc.

So, at a glance, this seems good. Nice clean DB entries with logically named nodes. If I could just do it this way, I'd be thrilled.
I'm seeing some quirks, but I think I might be able to iron them out.

cscase
August 4th, 2013, 06:52
Well, I think I have nearly got everything ironed out, but there's one intermittent idiosyncrasy I'm trying to flatten. I got the skills creating nicely named nodes in the database. And I also figured out how to reference them from my extra fields on the side!

But when starting with a new character, I end up with the skills that are referenced on the extra fields getting doubled. To use the same fleeing example, I would see Fleeing listed twice in skills. It's not actually getting doubled in the database, just showing twice in the skill list. And if I reload the ruleset, it will be no longer be doubled and be fine thereafter.

I think what is happening is a problem with the order in which the controls are initialized, maybe. The skill list appears first in my .xml, but it seems like maybe when those extra side controls initialize, the skill list hasn't been populated yet so they are going ahead and adding that node?

Is there a way to control the order in which things happen when a sheet first loads and database is getting set up?

Thanks!!!

cscase
August 4th, 2013, 07:32
Hah, well I thought I had figured it out, but actually still working on it.

cscase
August 4th, 2013, 08:13
I thought this had to do with the order things initialize in, but I'm no longer so sure about that. The skills that I reference on the extra controls on my sheet all appear twice in the list of skills when I create a new character. But this only happens on new characters. If I reload the ruleset, those characters thereafter are fine. And it's not doubling those skills in the db.xml; it's just showing them twice on the character sheet. I'm not sure at all what's happening here.

Trenloe
August 5th, 2013, 00:11
Without seeing all of your code I'm not sure where this could be coming from. Common things could be onUpdate triggering to execute code again, or onInit being ran more than once. Put some debugging code in your scripts (Debug.console is useful https://www.fantasygrounds.com/refdoc/Debug.xcp - and load the console with /console in the chat window) to see if functions/sections of code are being called twice.