PDA

View Full Version : Referencing a windowlist field in two places causes it to double on the list



cscase
August 18th, 2013, 01:32
Hey all,
I am really stumped on this one. Quick summary of the bug:
I am creating a windowlist that makes entries on a list of skills. All is well up to this point.

One of the skills is actually health, which is the character's HP, so I want that skill's value to show up in a HP box elsewhere on the sheet. So, I created a box for HP like this:


<numberfield name="hp" source=".skills.Health.pool">

Now, when I create a new character and open the sheet, I see Health listed as a skill twice. If I hit reload, everything's fine after that. So this only happens on a new character.

When the new character sheet is opened, the first thing that happens (I know this via debug messages I set up) is that the windowlist with skills is populated, by this code:


for k, t in pairs(skilldata) do
local matches = winlist[k];

if not matches then
Debug.chat('creating skill window '..k);
local newwin = createWindow("."..k);
newwin.label.setValue(k);
newwin.rating.setValue(t.rating);
newwin.pool.setValue(t.rating);
matches = { newwin };
end
end


This lists each one of the skills being created, and it only shows Health showing up ONE time.

After that, the HP box I mentioned above is initialized.

On the skill list, I have Health showing up TWO times. Reloading the ruleset makes the duplicate entry disappear. If I take away the source part on the HP box, the problem does not occur. So, my debug code is only showing me that I'm running a single createwindow for health, yet it's showing up twice, and somehow the source parameter for that HP box is making this happen. Is this a bug with my code or with FG? Any ideas?

edit: Also, I should add, I'm assigning health an initial value of 1, so that it doesn't start off as null. I read something in another thread that suggested that might help, but so far no love.

Moon Wizard
August 20th, 2013, 20:27
It's always challenging to reference a single field of a dynamically created list on a separate tab. In the 3.5E, 4E and PFRPG rulesets, I actually avoided this problem by only providing a roll button on the front page, and not trying to look up the actual ruleset numbers.

First, you should specify any default values in the skilldata variable, and have your code set the default value (if relevant) for the newly created skill record.

For debugging the issue, you may want to add Debug.chat calls in the numberfield onInit and right after the windowlist.createWindow calls to look at the database node associated to that control and that new window. You want to make sure that the databasenodes are identical between the control and the results of windowlist.createWindow.

Otherwise, we may need to get more details from your code to figure out what is going on.

Regards,
JPG