PDA

View Full Version : Creating an "alias" for a character sheet field / DB node?



cscase
November 3rd, 2013, 05:22
Question:
I'm trying to get a combat tracker working with the ruleset I've been putting together, but am running into a problem. For NPC entries, the values for things like HP are stored in the root of the object as "hp," which seems to be what the combat tracker is looking for, so for NPCs the HP value populates automatically when I drag an NPC into the tracker. So far, so good.


But for PCs, I have the HP value stored another layer or two deep in the database, and it has a slightly different name than just "hp." As a result, the combat tracker is not wanting to pick up values for PC HPs when I drag them in, and instead it just gives me a blank box with the chain links icon.


What is the best way to resolve this? I was thinking that maybe I could add an invisible control to the character sheet that is set with its source to be the DB node that contains player current HP. The idea being that this would be basically a "shortcut" to the HP and maybe the combat tracker would be able to reference the HP value through that. I set that up like this, but it doesn't seem to work:


<numberfield name="hp" source=".stats.Health.pool">
<anchored>
<to>hpframe</to>
<position>insidetopright</position>
<offset>0,0</offset>
</anchored>
<noreset />
<invisible />
</numberfield>


One thing I'm not 100% clear on is whether the CT is looking for a sheet control called "hp" or a DB node. If the latter, I guess I could put an onValueChanged call on my HP field that would write the new value into a DB node at the root of the character? Would that work? And if so, would it be horribly ghetto and a bad idea? It doesn't seem like a "best practice" sort of solution but I'm a bit over my head messing with the CT anyway so I'm willing to do whatever works for now :P

Or would there be an easier/better way to tackle this problem?

Moon Wizard
November 3rd, 2013, 07:55
You should look at the way it is handled in the 3.5E or 4E rulesets. The CT entries use the NPC data structure format, but link to the PC fields for PC entries.

Regards,
JPG

cscase
November 3rd, 2013, 21:08
Hrmm, hunting around I found this bit in manager_version2.lua. I don't understand it, but it looks like it may be relevant. Is this what you're talking about?


-- Copy node over to new location
-- And convert partial to full records
local sClass, sRecord = DB.getValue(vNPC, "link", "", "");
if sRecord == "" or sClass == "charsheet" then
DB.copyNode(vNPC, nodeNew);
if sClass ~= "charsheet" then
DB.setValue(nodeNew, "link", "windowreference", "npc", "");
end
else
local nodeRecord = DB.findNode(sRecord);
if nodeRecord then
DB.copyNode(nodeRecord, nodeNew);
end
DB.copyNode(vNPC, nodeNew);
DB.setValue(nodeNew, "link", "windowreference", "npc", "");
end

Perhaps part of my problem is that I don't understand what the ct_number_crosslink template is supposed to do. I see it creates a numeric field with the chain link graphic, I can see, but what is its purpose?

I can see that the CT is sort of a pretty complicated mass of code that I'll need to take one piece at a time to understand... I'm just not sure which piece I need to start with.

Moon Wizard
November 4th, 2013, 01:49
Search for "ct_number_crosslink" (with the quotes ) across all the files in the ruleset. You may need to download an editor with a good multi-file search feature, if you are not already using one. I use Notepad++.

You should find a template tag with that name somewhere in one of the ruleset files. I'm away from my machine, or I could look up.

The VersionManager script is only used for migrating data structures that change between ruleset versions, so not relevant in this case.

Regards,
JPG

cscase
November 4th, 2013, 02:55
AHA, I had looked at that template before, but I wasn't sure I was in the right place and apparently I followed the wrong referential rabbit trail from there and wound up lost in the woods. But now I've found the function below in ct_entry.lua and it looks like exactly what I needed. So I think I am on the right track now, thanks to your pointing me in the right direction. Thanks JPG!



function linkPCFields()
local nodeChar = link.getTargetDatabaseNode();
if nodeChar then
name.setLink(nodeChar.createChild("name", "string"), true);


hp.setLink(nodeChar.createChild("hp.total", "number"));
hptemp.setLink(nodeChar.createChild("hp.temporary", "number"));
nonlethal.setLink(nodeChar.createChild("hp.nonlethal", "number"));
wounds.setLink(nodeChar.createChild("hp.wounds", "number"));


grapple.setLink(nodeChar.createChild("attackbonus.grapple.total", "number"), true);

ac_final.setLink(nodeChar.createChild("ac.totals.general", "number"), true);
ac_touch.setLink(nodeChar.createChild("ac.totals.touch", "number"), true);
ac_flatfooted.setLink(nodeChar.createChild("ac.totals.flatfooted", "number"), true);
cmd.setLink(nodeChar.createChild("ac.totals.cmd", "number"), true);

fortitudesave.setLink(nodeChar.createChild("saves.fortitude.total", "number"), true);
reflexsave.setLink(nodeChar.createChild("saves.reflex.total", "number"), true);
willsave.setLink(nodeChar.createChild("saves.will.total", "number"), true);

sr.setLink(nodeChar.createChild("defenses.sr.total", "number"), true);


init.setLink(nodeChar.createChild("initiative.total", "number"), true);
end
end