PDA

View Full Version : Value based on source



Larhalt
December 7th, 2015, 23:02
Hi,

I'll try to explain as clear as possible my problem,
I have to set a value based on source, for example:

If strength from 1-8 set another field to "-3"
If strenght from 9-14 set another field to "0"
If strength from 15-18 set another field to "+3"

I have to put inside the record_char_main.xml so I need the <script> tag.
Can someone post an example script, I can do to the other statistic.

Thank you in advance.

Moon Wizard
December 7th, 2015, 23:37
You could look at the "number_abilityscore" template in the 5E ruleset as an example.

Basically, you need to capture the onValueChanged event on your Strength field (using script tag), and set the value of a different field to the correct value based on the new value of the Strength field.

Regards,
JPG

Larhalt
December 8th, 2015, 10:59
Thank you JPG, I've searched all over the 5E folder, but I only found this one in template_campaign.xml


<template name="number_abilityscore">
<basicnumber>
<default>10</default>
<script file="campaign/scripts/number_abilityscore.lua" />
</basicnumber>
</template>

If is this one that I have to check, I really can't understand how to use it :(

Edit:
Oh wait, maybe you mean this


function onValueChanged()
local nMod = math.floor((getValue() - 10) / 2);

I don't know how to use it, "If Strength <= n, then set value = n"

Moon Wizard
December 8th, 2015, 18:14
Creating ruleset code requires some basic XML and Lua programming skills, so you'll have to get familiar with Lua.

Perhaps something like the code below. It will have to be customized to fit the names of your fields



function onValueChanged()
local nValue = getValue();
local nMod = 0;
if nValue < 9 then
nMod = -3;
elseif nValue > 14 then
nMod = 3;
end
window.bonusfieldname.setValue(nMod);
end


Regards,
JPG

Larhalt
December 8th, 2015, 19:14
Thank you very much MW, it works perfectly, I just have to change the "<" and ">" chars like said in this post (https://www.fantasygrounds.com/forums/showthread.php?11395-Then-expected-near-lt-eof-gt&p=82148&viewfull=1#post82148).

Just a question, since the fields that are based on strength are 3, and "of course" they have different value based on strength value.
For example:

Strength = 15
Field 1 = +1
Field 2 = +3
Field 3 = +2

I tried to add another script as the same that you have wrote, but it only modified the last field.

Moon Wizard
December 8th, 2015, 19:26
You can only have one onValueChanged function. You'll need to have nMod, nMod2 and nMod3 calculated and assigned all one one function.

JPG

Larhalt
December 8th, 2015, 19:51
Thanks again MW, it's perfect. :)