Log in

View Full Version : Dividing stat and returning whole number (d20jpg)



GeneralChaos
June 30th, 2011, 08:05
I'm trying to make a self-populating maximum number field. I'm about 15 years out of practice with anything remotely resembling programming, so have used a looted AC armor dex mod script.

I am hoping to get: Divide charisma score by 4, rounded down.
It's just returning 0.



<source>
<name>abilities.charisma.score</name>
</source>
<script>
function onSourceUpdate()
setValue(calculateSources());
end

function onSourceValue(source, sourcename)
local cha = source.getValue();
cha = cha / 4;
return cha;
end
</script>

Moon Wizard
July 1st, 2011, 09:28
The particular template you are using is expecting an "op" tag for each source.

Try this:


<source>
<name>abilities.charisma.score</name>
<op>+</op>
</source>
<script>
function onSourceUpdate()
setValue(calculateSources());
end

function onSourceValue(source, sourcename)
local cha = source.getValue();
cha = cha / 4;
return cha;
end
</script>


Cheers,
JPG