PDA

View Full Version : Combine values



statik37
August 3rd, 2019, 21:12
Can someone point me in the direction to figure out the code to take two values entered on a sheet, add them together, and input the total into a third cell?

I am currently developing a ruleset for Star Trek Adventures, and I would like to automate some of the stuff. In STA, the total stress for your character is equal to your fitness stat plus your security stat.

Thank you for your help.

Trenloe
August 3rd, 2019, 22:06
I’m not in front of my computer so can’t paste the exact code. But there are GUI controls in different rulesets that add together data from other fields.

Look in the 5E ruleset at the ac.total field (I’m guessing the control might be called actotal) in the character sheet.

Or, if you want to do it in code then use two getValue commands followed by one setValue.

Trenloe
August 3rd, 2019, 22:46
I'm briefly in front of a computer... Have a look at the template "number_chartotalcurrenthp" in the 5E ruleset, campaign\template_char.xml file. This is an example of a way of using the <source> command to source data from another database field, it has the <op> property that specifies if that field is an addition or subtraction from the field total.

Do a find in files in most rulesets for <op> to see other examples.

Ranzarok
August 4th, 2019, 02:01
Not sure if this is what you are wanting to do but this is how I did it for my Conan extension:

https://i.imgur.com/C15VdtJ.png

Here I am taking the Willpower number (7), adding the Expertise number (1) and putting the result in the "TN" number box.

code for this block:

<frame_char name="willpowerframe">
<bounds>421,313,200,95</bounds>
</frame_char>

<string_label name="willpower" >
<anchored to="willpowerframe" position="insidetopleft" offset="15,10" width="80" />
<default>WILLPOWER</default>
<tooltip textres="need new textres" />
</string_label>

<basicnumber name="willpowerstat" source="willpowerstat">
<anchored to="willpowerframe" position="insidetopleft" offset="140,13" width="20" height="17"/>
</basicnumber>



<string_label name="willpowerlabel" >
<anchored to="willpowerframe" position="insidetopleft" offset="20,30" width="180" />
<default>Skill..............EX.......FC......TN</default>
<font>SmallHeader-8</font>
<tooltip textres="need new textres" />
</string_label>

<string_label name="disciplinelabel">
<anchored to="willpowerframe" position="insidetopleft" offset="15,45" />
<default>Discipline</default>
</string_label>

<basicnumber name="disciplineex">
<anchored to="willpowerframe" position="insidetopleft" offset="82,47" width="15" height="15"/>
<script>
function onValueChanged()
local rActor = ActorManager.getActor("pc", window.getDatabaseNode());
Debug.console("rActor: ");
Debug.console(rActor);

local nodeWin = window.getDatabaseNode();
Debug.console("nodeWin: ");
Debug.console(nodeWin);

local attribscore = nodeWin.getChild("willpowerstat").getValue();
Debug.console("attribute: ");
Debug.console(attribscore);

local EX= nodeWin.getChild("disciplineex").getValue();
Debug.console("EXPT: ");
Debug.console(EX);

nodeWin.getChild("disciplinetn").setValue(attribscore+EX);
end
</script>
</basicnumber>

<basicnumber name="disciplinefc" source="disciplinefc">
<anchored to="willpowerframe" position="insidetopleft" offset="110,47" width="15" height="15"/>
</basicnumber>

<basicnumber name="disciplinetn" source="disciplinetn">
<anchored to="willpowerframe" position="insidetopleft" offset="140,47" width="20" height="15"/>
</basicnumber>


Hope this helps you.

celestian
August 4th, 2019, 05:09
Do you mean something like this via XML?



<template name="number_chartotalac">
<number_chartotal>
<description textres="armorclass" />
<font>reference-b-large</font>
<modifiersize>mini</modifiersize>
<modifierfield>defenses.ac.temporary</modifierfield>
<source><name>defenses.ac.base</name><op>+</op></source>
<source><name>defenses.ac.armor</name><op>+</op></source>
<source><name>defenses.ac.shield</name><op>+</op></source>
<source><name>defenses.ac.misc</name><op>+</op></source>
</number_chartotal>
</template>

statik37
August 5th, 2019, 14:18
Thank you, that is all very helpful. I may have more questions going forward. I'm creating my first ruleset, and I am only a novice when it comes to coding.