Math Coding Question - Character Attribute Profile

Be sure to read and follow the guidelines for our forums.

Jun 16, 2025 10:49 am
Hi!

I wondered if someone could check my code and clarify a couple of quuestions

I have coded the Attribute Profile of my Custom Character Sheet and tested it and it seems to be working most of the ime.
https://i.imgur.com/q8DcryE.png

However, I had to fudge the code slightly to get it to work, and I'm wondering if I missed a trick that would have made it simpler.

Most of the math is pretty simple:

- Add the Character Generated Attribute Value to the Advances Taken and calculate the Current Attribute Value.

The complication arosewith the Calculation of the 'Wounds' (W)

The actual calculation is SB+(2xTB)+WPB. Which is Strength Bonus + Double the Toughness Bonus + Willpower bonus but I don't think the code available is that flexible.

The Closest I could get was Wounds: =

Where I had to

1. Explicitly add all of the components individually because there was no way of referencing the totals in the CURRENT PROFILE row.
2. Add all the toughness values (T & AT) twice because +((T+AT)x2) didn't seem to work.
3. Although the sheet is working I notice that the Wounds Calculation is finicky. If any of the values for S, AS, T, AT WP or AWP, are blank it refuses to calculate because it claims there is a missing value. Even though the other calculations seem willing to accept a blank space as a zero.
4. Also the actual result ought to be based on the 'Bonus Value' of the attribute rather than the full value. The Bonus Value being the 'Ten Digit e.g. the SB of 34 = 3. but I couldn't imagine how to do that, so I tried dividing the output by 10, which I figured was close enough, but couldn't get it to work either.

The actual calculation for Wounds ought to be SB3 + TB12+WPB9 = 24

Just wondering if there is a better way of doing it or if I've missed a track somewhere.
[ +- ] Attribute Profile Code
Last edited June 16, 2025 4:13 pm
Jun 16, 2025 12:31 pm
when doing math with multiple variables, things break down when the variables are blank (data type issue). Type in "0" where there there normally would be blank values

blank values are read a text and number+text = concatination, insted of addition
Last edited June 16, 2025 12:33 pm
Jun 16, 2025 1:53 pm
You can use conditional logic to evaluate fields.
_a1$=(a>0)?a:0
Then use a1 and it should always be valid
Jun 16, 2025 2:32 pm
Psybermagi says:
... Then use a1 and it should always be valid
Unless a was negative. :(
Jun 16, 2025 2:50 pm
Fine make it complicated then :(
_a1$=(a>0)?a:(a<0)?a:0
_a1$=(a>0)?a:((-1*a)>0)?a:0
But same principle.
Jun 16, 2025 4:17 pm
vagueGM says:
Psybermagi says:
... Then use a1 and it should always be valid
Unless a was negative. :(
In theory it should never be a negative. Although I did test what would happen if I entered a negative advance (e.g. 'A Curse' or perhaps a 'Disability') and it seemed to work.
Psybermagi says:
Fine make it complicated then :(
_a1$=(a>0)?a:(a<0)?a:0
_a1$=(a>0)?a:((-1*a)>0)?a:0
But same principle.
Can you clarify where I add this extra conditional coding?

Does it have to be inserted into every _$= data field?

Also, is there a list of these conditional codes somewhere?
Last edited June 16, 2025 4:21 pm
Jun 16, 2025 4:29 pm
I often have cleanup for form field data entry immediately after the field or just before it is used for the next calculation, within a hidden or collapsed section.
The BCC guide (see form field at the end) and GM sheet guide have most of this documented.

The basics are (remove spaces)
[ _ D $ = ( A > 0 ) ? b : C
Form field with
Variable D =
$ tells GP to evaluate the right side
() Standard math order of operation
( A > 0 ) evaluated due to ?
B if true
C if false
Last edited June 16, 2025 4:40 pm
Jun 16, 2025 4:38 pm
I managed to get the 'Wound Calculation' working as intended.
https://i.imgur.com/KFTcapO.png

That was entirely my fault as I tried to use the normal division symbol rather than the / backslash to indicate divide.

  Wounds (SB+(2xTB)+WPB): [_$=(S+AS+T+T+AT+AT+WP+AWP)/10] 

Sorted it, and managed to simplify the coding whilst actually adding more potential.
https://i.imgur.com/JYNMZoU.png

I was trying to use @psbermagi's coding solution and got myself in a bit of a mess. Then I realised that if I could assign variables to calculated outcomes, then not only could I assign a variable to the 'Wounds calculation' (which might come in handy elsewhere on the character sheet). But I could aassign variables to all of the 'Current Attribute Values' on the bottom row of the 'Attribute Profile'. That in turn would make the calculation of 'Wounds' simple because the Current Attribute values will always be greater or less then zero. So, the conditional statements aren't necessary.

The revised coding for the 'Wounds' calculation becomes relatively simple.
Wounds: [_W$=(CS+(CT*2)+CWP)/10]

where
W Wounds Pool
CS Current Strength
CT Current Toughness
CWP Current Willpower

None of these should ever be blank data fields on an active character.
Last edited June 16, 2025 5:44 pm
Jun 16, 2025 6:40 pm
Didz says:
... The Bonus Value being the 'Ten Digit e.g. the SB of 34 = 3 ...
You can do this by dividing by 10 and then rounding down using the floor function:
if CS is your current strength, and you want SB to be the bonus then:
_SB$=floor(CS/10)
Jun 17, 2025 4:10 am
Didz says:
.... None of these should ever be blank data fields on an active character.
And if anyone ever leaves one blank, it will be pretty obvious, so they can fix it. No need for defensive formula (but we don't know these details).
Jun 17, 2025 7:30 am
Chalrytharendir says:
Didz says:
... The Bonus Value being the 'Ten Digit e.g. the SB of 34 = 3 ...
You can do this by dividing by 10 and then rounding down using the floor function:
if CS is your current strength, and you want SB to be the bonus, then:
_SB$=floor(CS/10)
Thanks! I shall bear that in mind, although in this instance it's not that much of an issue, and in many ways, if a character's strength was S:39, I'd rather the 0.9 was included in the calculation than discarded. I think the reason the RAW discards the units from the calculation was just to reduce the mental strain of the arithmetic on the player. But now the character sheet is doing it automatically, that's not a problem.
vagueGM says:
Didz says:
.... None of these should ever be blank data fields on an active character.
And if anyone ever leaves one blank, it will be pretty obvious, so they can fix it. No need for defensive formula (but we don't know these details).
Yes! It would be obvious and easy to spot at a glance. Hence, the simpler solution becomes possible.

In truth this is a bit like the blind leading the blind because whilst not everyone reading this thread would know that every Attribute on a WFRP Character Profile has to have a 'Current Value', I didn't know, until it was mentioned, in one of the responses that it is possible to assign a variable code to a calculated value. It was that additional knowledge gained by studying the responses to my question that helped me discover the simpler solution based on my knowledge of the WFRP game system. I would never have sorted it without everyone's help, and I've learned a lot about the coding system in the process, which wasn't obvious even after hours of studying Adams BBcode guide, and watching all the videos.
Last edited June 17, 2025 7:42 am

You do not have permission to post in this thread.