PDA

View Full Version : Adding numberfields



Insanity
March 4th, 2013, 05:03
How does one go about adding several numberfields up and having that value being assigned to another numberfield?

I would like to total up 4 numberfields to one. Each one has a source name, but do not know if this can be done via xml or if lua is needed.

Moon Wizard
March 4th, 2013, 09:54
Lua script is definitely needed, since the underlying database system has no concept of "linked" fields.

Check out the "number_linked" template in the 3.5E and 4E rulesets for an example, or just borrow that template.

Regards,
JPG

Insanity
March 4th, 2013, 13:48
Looks like there is a few templates involved for this.

From what I see I need to copy two of the lua files?
"charsheet_linkednumber.lua"
"charsheet_totalwithability.lua"

There are a few templates as well?

On the 4E "charsheet_combat.xml", the total init bonus is defined as "<number_charinit>".
Looking in the "template_charsheet_combat.xml" file, that template has another template called "<number_chartotalwithability>" and this is where the math operations and sources are defined. The template "<number_chartotalability>" is defined in the "template_charsheet_general.xml" file and references the "charsheet_totalwithability.lua" file. The "<number_linked>" template is there as well.

In order for the "number_linked" to function, it looks that each template name must begin with "number-"? Is that correct?

Moon Wizard
March 4th, 2013, 19:15
No, a template name can be any valid XML string.

The only requirement to use the number_linked template is to include the template definition and the script file referenced in the definition.

The other templates that you see that are built on top of the number_linked template are essentially just examples of use, and how to layer templates.

Regards,
JPG

Insanity
March 18th, 2013, 01:14
It's been a short while, but been able to get back at this.

I have the 'charsheet_linkednumber.lua' in the ruleset, and being loaded in the 'charsheet.xml'

I then have the following template defined;



<template name="number_linked">
<number>
<readonly />
<source mergerule="resetandadd" />
<script file="scripts/charsheet_linkednumber.lua" />
</number>
</template>


Looking at the 4E ruleset then, looks like I use the operators as follows;



<source>
<name>source_name</name>
<op>+</op>
</source>


I have this within the numberfield control tags, named 'total_initiative_bonus. When I load the 'charsheet_combat' page that has the code, I get the following error.



Script Error: [string "charsheet_combat:total_initiative_bonus"]:1: Invalid argument to getChild