Averaging stats together?

Just curious if there is a way to average stats together in order to make an entirely new stat. Then display it in the stat screen. Say for instance I have the overarching stat of ship health, but I want to break it down into bridge integrity, aft section integrity, etc. Could I average all the parts of the ship into a new stat which shows the overall ship health?

Add all the “parts” together and then divide by the total number of parts to get the combined average. Do this calculation whenever any of the parts has a change in value to keep the combined average always up to date.

In startup you would do something like this:

``````
*create bridge_left 20
*create bridge_right 30
*create bridge_integrity 0
*set bridge_integrity (bridge_left + bridge_right) / 2

``````

And then in stat:

``````
*stat_chart
text bridge_left Bridge Left
text bridge_right Bridge Right
text bridge_integrity Bridge Integrity

``````

tried what you said but I got this error

line 41: Invalid expression at char 20, expected closing parenthesis, was: OPERATOR [+]

It is definitely referring to the

*set bridge_integrity (bridge_left + bridge_right) / 2

Try

*set bridge_integrity ((bridge_left) + (bridge_right))/2

Whereas this will work as Nocturnal_Stillness has written, depending on the number of variables you add, you could end up with a very long decimal place after your answer.

Eg:
*set bridge_left 90
*set bridge_right 100
*set bridge_middle 100
Set bridge_integrity (((bridge_left)+(bridge_right))+(bridge_middle))/3

This would set bridge_integrity as 290/3 = 96.66666666666666666666666666666

There is a long winded way to round this up/down but is there a choicescipt command to do that? Is there a command *round ?

@andymwhy Just like so:

Set bridge_integrity round((((bridge_left)+(bridge_right))+(bridge_middle))/3)

Note the extra parentheses to round the whole sum.

Oh, now that there is some useful knowledge. Thanks, @Vendetta - been wondering about rounding for a while, don’t know why I didn’t ask the forums…

@Havenstone It’s just something I had to figure out ages ago, as Vendetta’s character finances used to produce values not entirely unlike andy’s figure there… *cough*

I have to agree with your sentiment though – I often don’t even think to ask here, and instead subject myself to an awful lot of hair-pulling, teeth-gnashing and cat-kicking… (only j/k on the last bit, honest!).