PDA

View Full Version : Order of calculation for number_linked control



Mephisto
May 7th, 2022, 08:46
Hi there,
I encountered an issue when using a number_linked control using a multiplicator.

The template I build looks like this:

<template name="number_charsprint">
<number_linked>
<font>reference-b-large</font>
<modifiersize>mini</modifiersize>
<modifierfield>sprint.temporary</modifierfield>
<description textres="char_tooltip_sprint" />
<source><name>speed.base</name><op>+</op></source>
<source><name>speed.bonus</name><op>+</op></source>
<source><name>speed.misc</name><op>+</op></source>
<source><name>encumbrance.bulkhalved</name><op>-</op></source>
<source><name>speed.sprintfactor</name><op>*</op></source>
<source><name>encumbrance.bulk</name><op>-</op></source>
<min>4</min>
</number_linked>
</template>

I was hoping the number_linked.lua logic in CoreRPG would run through the sources from top to bottom but it seems this is not what is happening. Core seems to populate an array and runs through the array in order of the items stored there. As long as all operators are simply additions or subtractions that's not a problem but I use a multiplicator in the template. That multiplicator is now called at a different time than intended, resulting in a total different result.

52689

Taking the above example, the correct calculation logic is "(Speed base + Sped Misc - Half Bulk) * Factor - Bulk" but what get calculated is "(Speed Base - Bulk - Half Bulk) * Factor + Speed Misc + Speed Bonus".
Any idea how I can influence the order of calculation without re-writing the CoreRPG function?

superteddy57
May 7th, 2022, 11:57
You might want to try and just override the calculation instead. Here is an example:

52690

Moon Wizard
May 7th, 2022, 15:29
Yeah, the way the number_linked control script was originally built (before my time) is as a very blunt instrument. Even though the code shows support multiplication/division, it doesn't really work without doing as @superteddy57 suggests.

Regards,
JPG