PDA

View Full Version : Help using different abilities for saves



Archmage
May 7th, 2008, 12:13
I'm trying to give the player the option to change which ability score is used for their saves. I've been pulling my hair out over this, because A) this whole "sources" thing seems very static and unwieldy, and B) I can completely remove parts of the code from the Save total fields, and it still works exactly like it did before, as though that code has no real purpose.

For example: this script in the charsheet_templates.xml file is located in the "save" template, which is used for the save total on the combat page of the character sheet. You can completely remove all of the bold lines, which supposedly are linking the related values and ability score to the save total, and yet the save total continues to function normally. Why is that? Where are these sources being added from?

<script>
function onInit()
addSourceWithOp("saves." .. root[1] .. ".base", "+");
addSourceWithOp("saves." .. root[1] .. ".misc", "+");
addSourceWithOp("saves." .. root[1] .. ".temporary", "+");

addSourceWithOp("abilities." .. stat[1] .. ".bonus", "+");

super.onInit();
end
</script>

What I want to do is have the player be able to click on the stat bonus for a given save on the combat page, and it should cycle between 2 stats. I want all the totals to update using whatever stat the player has selected (I don't think this whole "addSources" thing is going to work for that). So far, this has proved rather difficult.

I attempted to look at the skills sheet because I know custom skills can be set to use any stat. However, trying to decipher the workings of that convoluted uncommented spaghetti code just doesn't seem worth it. If somebody has already managed to understand how that works, I'd really appreciate an explanation.

joshuha
May 7th, 2008, 12:28
You could have multiple sources declared and the chooser you make just chooses among which ones is the active one.

But in general for something like this it is best to use your own control and declare your sources on your own. Do you need help with how to setup a database update handler?

Archmage
May 7th, 2008, 12:52
Well, I think I understand the handler functions. It's just someNode.onUpdate = myFunction(); right?

When you say "which one is the active one", does that mean you can choose which sources in a list of sources are active? Meaning it will only add the active one when calculating the total. If so, how do you do that?

edit:

Ok, I have a workable solution for now, which is just forcing FG to use the higher of the 2 stats. Here's the script for that. The control contains a <source> tag with the alternate ability bonus and no <op> tag.


function onSourceUpdate()
setValue(10 + calculateSources());
end

function onSourceValue(source, sourcename)
if sourcename == "abilities.wisdom.bonus" then
local wis = source.getValue();
local cha = sources["abilities.charisma.bonus"].getValue();

if wis == cha or wis > cha then
return wis;
else
return cha;
end
else
return super.onSourceValue(source, sourcename);
end
end


What I'd really like though is a way to set these globally, so it always uses the same stat for all the controls that show saves. Also, I'm not sure how to get the stat control in the Saves frame of the combat page to display the stat that's being used. It always displays the default stat. Any help there would be appreciated.

joshuha
May 12th, 2008, 14:59
Well as far as setting globally, in the temaplte for the saves you could make an XML field that you could put in a list of which fields it would look at. Then the onInit function would read the value of the control at runtime to see which 2 DBnodes it should look at and set handlers to them. I will see if I can come up with some example code on that later but essentially the save template already looks at an XML field called stat. You could change that to stat1 and stat2 and have similar logic as above to pick the best one.

As far as the second part about which stats, you would need to build the same logic into the "...statbonus" fields.