PDA

View Full Version : Help: Simple Number Counter



Alanrockid
July 26th, 2016, 12:47
New question ... I'm trying to implement a point counter on the character sheet, similar to the total loaded weight field (CoreRPG Ruleset).
I've been looking at record_char_inventory.xml and found this:



<simplenumber name="encumbranceload" source="encumbrance.load">
<anchored to="encumbranceframe" position="insidetopleft" offset="160,30" width="55" height="20" />
<frame name="fieldlight" offset="7,5,7,5" />
<readonly />
</simplenumber>


From what I understand, the weight counter is a numeric field that is set to display the value of a certain source, in this case "encumbrance.load".

Where is this source?

For example: I have numeric fields A, B and C. I want the sum of these three elements displayed in numeric field "D". I guess i need to store the values of A,B and C somewhere so D can read this as a source???
How should I proceed?

Thanks in advance for any help.

damned
July 26th, 2016, 13:37
Add some equipment with weight to the Inventory. Give the equipment names like BBBB, CCCC and DDDD and then /save in chat. Open the db.xml and you will see where how these were saved.
Next you want to find the code that accepted them. You want to use notepad++ (or any similar tool) and its Find in Files feature, an unpacked copy of CoreRPG and start tracking down the code that works for Inventory. Inventory is more complex than some code as it uses lists but thats ok - you will find your code :)

Andraax
July 26th, 2016, 14:43
And inventory has lots of derived classes in the various rulesets. Which ruleset are you using?

Trenloe
July 26th, 2016, 15:08
Where is this source?
In the campaign database. More info on the FG database here: https://www.fantasygrounds.com/modguide/database.xcp

Alanrockid
July 26th, 2016, 19:58
In the campaign database. More info on the FG database here: https://www.fantasygrounds.com/modguide/database.xcp

I actually forgot that db.xml is located outside the ruleset folder... silly mistake, right?

But that being said, things are working as intended now. I've already managed to make a simple numeric counter for basic attributes. Thank you for the help! :D

Alanrockid
July 26th, 2016, 19:58
And inventory has lots of derived classes in the various rulesets. Which ruleset are you using?

CoreRPG

Alanrockid
July 26th, 2016, 20:02
Add some equipment with weight to the Inventory. Give the equipment names like BBBB, CCCC and DDDD and then /save in chat. Open the db.xml and you will see where how these were saved.
Next you want to find the code that accepted them. You want to use notepad++ (or any similar tool) and its Find in Files feature, an unpacked copy of CoreRPG and start tracking down the code that works for Inventory. Inventory is more complex than some code as it uses lists but thats ok - you will find your code :)

And i've found it, indeed! XD

Do you believe i was actually using windows notepad this whole time? I've followed your advice, including using notepad++, now i feel silly for not doing this ages ago. hahahaha. Things are working as intended now. Thank you for your help! :D

Alanrockid
July 26th, 2016, 21:53
So... another question.
I have this simple numeric counter getting the info from the "forca" in db.xml. It works as intended.



<simplenumber name="maxencumbranceload" source="forca">
<anchored to="encumbranceframe" position="insidetopleft" offset="160,60" width="55" height="20" />
<frame name="fieldlight" offset="7,5,7,5" />
<readonly />
</simplenumber>


Here's the db.xml relevant info:



<forca type="number">4</forca>
<resistencia type="number">3</resistencia>
<habilidade type="number">1</habilidade>
<inteligencia type="number">1</inteligencia>


I want to get the sum of multiple sources, like "Forca"+"Resistencia", but i can't write the source as a attribute in the simplenumber tag because it only allows a single entry, is this right?
Searching the template_char in the 3.5E ruleset i have found this:



<number_linked>
<frame name="fieldlight" offset="7,5,7,5" />
<displaysign />
<rollable />
<hideonvalue>0</hideonvalue>
<source><name>stat</name><op>+</op></source>
<source><name>state</name><op>+</op></source>
<source><name>...encumbrance.armormaxstatbonusactive</name></source>
<source><name>...encumbrance.armorcheckpenalty</name><op>+</op></source>
<source><name>ranks</name><op>+</op></source>
<source><name>misc</name><op>+</op></source>


However, if i do something like this in my ruleset nothing happens...



<simplenumber name="maxencumbranceload">
<source><name>forca</name><op>+</op></source>
<anchored to="encumbranceframe" position="insidetopleft" offset="160,60" width="55" height="20" />
<frame name="fieldlight" offset="7,5,7,5" />
<readonly />
</simplenumber>


What am i doing wrong?

Trenloe
July 26th, 2016, 23:14
You only have one <source> defined - "forca" and no other sources being added using <op>, so this will only display the data held in forca, it won't add anything else to it. This also assumes that the "forca" database field is accessible from the database node that the window is anchored to.

Alanrockid
July 26th, 2016, 23:20
You only have one <source> defined - "forca" and no other sources being added using <op>, so this will only display the data held in forca, it won't add anything else to it. This also assumes that the "forca" database field is accessible from the database node that the window is anchored to.

I have used just one source as an example, because when i use <whatever source="forca"> it works ok, but when i do <whatever><source>forca</source></whatever> or <whatever><source><name>forca</name></source></whatever> it does nothing... should'nt it be the same thing? I'm a little confused by this...

Trenloe
July 26th, 2016, 23:35
The <simplenumber> control template won't work, it does not have the code to use the multiple <source> and <op> properties. You need to use the <number_linked> control template.

Alanrockid
July 28th, 2016, 13:56
The <simplenumber> control template won't work, it does not have the code to use the multiple <source> and <op> properties. You need to use the <number_linked> control template.

Thats it! It worked! Thank you! :D

Also, is there any way to do some slightly more complex operations, like Attribute*2 + attribute2*3?

Trenloe
July 28th, 2016, 16:49
Also, is there any way to do some slightly more complex operations, like Attribute*2 + attribute2*3?
The code steps through each <source> entry in order and applies the <op> mathematical function using the value of the database field pointed to by <source><name>. Supported <op> mathematical functions are: +, -, *, - and neg+ (only add the value of the source if it is negative).

So, from this, you can't do "Something * 2" unless you have a database field containing "2" that you can point the source to. Plus, the process doesn't follow the mathematics BODMAS (https://www.mathsisfun.com/operation-order-bodmas.html) order for processing, so you can't do "Attribute*2 + attribute2*3".

If you want to do mathematical calculations like this then you'll probably have to look at writing the code in LUA and using onUpdate event handlers against the sources to trigger an update in the target field. See "Handler functions" here: https://www.fantasygrounds.com/modguide/scripting.xcp Or have intermediate <number_linked> fields that store their result in the database and then use these database fields in the final result. e.g. one <number_linked> field to calculate Attribute*2, one <number_linked> to calculate attribute2*3 and a final <number_linked> field to add the two together. You can make the first two fields invisible so they aren't shown on the GUI. But this would be quite a complex approach to something that could be covered in LUA using handler functions.