PDA

View Full Version : Best Way to Add New Source Tag to Skill Bonuses? Merging Question...



SieferSeesSomething
June 11th, 2025, 05:16
I'm trying to add a new type of bonus that gets added to a character's skill (in addition to their ability score, trained bonus, armor check penalty, and misc bonus) for a DnD 4e extension. I've managed to add the bonus as a new tag to each individual skill in the skill list in the database, but I can't figure out the best way to merge windowclasses or templates or whatever to make that database value get added to the skill total value.

After doing some investigation, here's what I found.

I found record_char_skill.xml. In there, I found the charsheet_skills windowclass and char_skill windowclass. In there, in the sheetdata tag, I found this:


<number_charskilltotal name="total">
<anchored width="44" height="20">
<top offset="2" />
<right parent="rightanchor" anchor="left" relation="relative" offset="-5" />
</anchored>
</number_charskilltotal>

Which led me to this template:



<template name="number_charskilltotal">
<number_linked_framed>
<displaysign />
<rollable />
<hideonvalue>0</hideonvalue>
<source>
<name>stat</name>
<op>+</op>
</source>
<source>
<name>...encumbrance.armorcheckpenalty</name>
<op>+</op>
</source>
<source>
<name>...levelbonus</name>
<op>+</op>
</source>
<source>
<name>trained</name>
<op>+</op>
</source>
<source>
<name>misc</name>
<op>+</op>
</source>
<script>
function onSourceValue(source, sourcename)
if sourcename == "trained" then
if DB.getValue(source) == 1 then
return 5;
end
return 0;
elseif sourcename == "...encumbrance.armorcheckpenalty" then
if StringManager.contains({"strength", "dexterity", "constitution"}, DB.getValue(window.getDatabaseNode(), "statname", "")) then
return math.min(DB.getValue(source), 0);
end
return 0;
end

return super.onSourceValue(source, sourcename);
end

function action(draginfo)
local nodeWin = window.getDatabaseNode();
if nodeWin then
local rActor = ActorManager.resolveActor(DB.getChild(nodeWin, "..."));
local sLabel = DB.getValue(nodeWin, "label", "");
local sStat = DB.getValue(nodeWin, "statname", "");
ActionSkill.performRoll(draginfo, rActor, sLabel, getValue(), sStat);
end
return true;
end

function onDragStart(button, x, y, draginfo)
return action(draginfo);
end

function onDoubleClick(x,y)
return action();
end
</script>
</number_linked_framed>
</template>


Which leads to this template:

<template name="number_linked_framed">
<number_linked>
<frame mergerule="replace" name="fieldlight" offset="7,5,7,5" />
</number_linked>
</template>

So it seems that I need to be able to add a new type of source to that list of sources I bolded above in the number_charskilltotal template under the number_linked_framed. I've tried combinations of merging the windowclass and templates and can't get it to add. Except once, when it added ONLY my bonus, and none of the other bonuses that exist now lol. Any advice is appreciated!

SieferSeesSomething
June 11th, 2025, 05:32
Just to start us off, I'll throw out a couple things I've tried that I know don't work:


<windowclass name="char_skill" merge="join">
<sheetdata>
<number_charskilltotal name="total" merge="join">
<number_linked_framed>
<source>
<name>race</name>
<op>+</op>
</source>
</number_linked_framed>
</number_charskilltotal>
</sheetdata>
</windowclass>

and


<template name="number_charskilltotal" merge="join">
<number_linked_framed>
<source>
<name>race</name>
<op>+</op>
</source>
</number_linked_framed>
</template>

This one is closest so far. I thought it only added the new bonus, but I might be wrong. It doesn't seem to add the stat ability bonus to the skill for some reason, but it least adds the trained and misc bonuses. Not sure why. But also I recall reading in some forum post it might be bad practice to modify templates and I should try to modify the windowclass if possible?

EDIT: I think I might have realized why it's adding everything but the ability score stat. It's replacing the first source tag isn't it? And that's the first source tag in there? Not positive if that's correct, but sounds like something I read from one of the developer docs.

DCrumb
June 11th, 2025, 07:24
If I am remembering this correctly, if you are override an element in the window class, you need to specify all of the items in the element. So instead of trying to join on the number_charskilltotal, you have to write it all out and add in your piece.

Trenloe
June 11th, 2025, 15:32
You want to add the additional source to the control when you use the template "number_charskilltotal". Try this:


<windowclass name="char_skill" merge="join">
<sheetdata>
<number_charskilltotal name="total">
<source>
<name>race</name>
<op>+</op>
</source>
</number_charskilltotal>
</sheetdata>
</windowclass>

See here for details on template merge behavior: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644511/Ruleset+-+Templates+for+code+re-use#Merge-Behavior

SieferSeesSomething
June 11th, 2025, 17:08
You want to add the additional source to the control when you use the template "number_charskilltotal". Try this:


<windowclass name="char_skill" merge="join">
<sheetdata>
<number_charskilltotal name="total">
<source>
<name>race</name>
<op>+</op>
</source>
</number_charskilltotal>
</sheetdata>
</windowclass>

See here for details on template merge behavior: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644511/Ruleset+-+Templates+for+code+re-use#Merge-Behavior

That was it! I was so close.

I guess I didn't need to include the <number_linked_framed> tag underneath my <number_charskilltotal> one and could've just jumped to the <source> tag. That's good to know. I guess I had to think of it as all the non-named lower level templates getting replaced at once maybe.

Thanks so much for the help!

Trenloe
June 11th, 2025, 17:29
I guess I had to think of it as all the non-named lower level templates getting replaced at once maybe.
Yep, that's the thing. Mult-tiered templates inherit the data from the lower tiers - you don't need to include the lower tier template names, just the name of the top level template you're using.