# Averaging stats together?

**URL:** <https://forum.choiceofgames.com/t/averaging-stats-together/1960>\
**Category:** ChoiceScript Help\
**Created:** [December 9, 2013, 1:42am UTC](https://forum.choiceofgames.com/t/averaging-stats-together/1960 "2013-12-09T01:42:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![crispo05](https://avatars.discourse-cdn.com/v4/letter/c/e36b37/32.png) [@crispo05](https://forum.choiceofgames.com/u/crispo05)\
**Post date:** [December 9, 2013, 1:42am UTC](https://forum.choiceofgames.com/t/averaging-stats-together/1960/1 "2013-12-09T01:42:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![P\_Tigras](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/p_tigras/32/626_2.png) [@P\_Tigras](https://forum.choiceofgames.com/u/P_Tigras)\
**Post date:** [December 9, 2013, 3:11am UTC](https://forum.choiceofgames.com/t/averaging-stats-together/1960/2 "2013-12-09T03:11:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fantom](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/fantom/32/8537_2.png) [@fantom](https://forum.choiceofgames.com/u/fantom)\
**Post date:** [December 9, 2013, 9:24am UTC](https://forum.choiceofgames.com/t/averaging-stats-together/1960/3 "2013-12-09T09:24:04Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![crispo05](https://avatars.discourse-cdn.com/v4/letter/c/e36b37/32.png) [@crispo05](https://forum.choiceofgames.com/u/crispo05)\
**Post date:** [December 9, 2013, 6:19pm UTC](https://forum.choiceofgames.com/t/averaging-stats-together/1960/4 "2013-12-09T18:19:54Z")

</div>

tried what you said but I got this error

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

---

<div class="post-metadata">

**Author:** ![crispo05](https://avatars.discourse-cdn.com/v4/letter/c/e36b37/32.png) [@crispo05](https://forum.choiceofgames.com/u/crispo05)\
**Post date:** [December 9, 2013, 6:23pm UTC](https://forum.choiceofgames.com/t/averaging-stats-together/1960/5 "2013-12-09T18:23:57Z")

</div>

It is definitely referring to the

\*set bridge\_integrity (bridge\_left + bridge\_right) / 2

---

<div class="post-metadata">

**Author:** ![Nocturnal\_Stillness](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/nocturnal_stillness/32/100414_2.png) [@Nocturnal\_Stillness](https://forum.choiceofgames.com/u/Nocturnal_Stillness)\
**Post date:** [December 9, 2013, 6:35pm UTC](https://forum.choiceofgames.com/t/averaging-stats-together/1960/6 "2013-12-09T18:35:41Z")

</div>

Try

\*set bridge\_integrity ((bridge\_left) + (bridge\_right))/2

---

<div class="post-metadata">

**Author:** ![andymwhy](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/andymwhy/32/34396_2.png) [@andymwhy](https://forum.choiceofgames.com/u/andymwhy)\
**Post date:** [December 9, 2013, 6:47pm UTC](https://forum.choiceofgames.com/t/averaging-stats-together/1960/7 "2013-12-09T18:47:51Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Vendetta](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/vendetta/32/533_2.png) [@Vendetta](https://forum.choiceofgames.com/u/Vendetta)\
**Post date:** [December 9, 2013, 7:08pm UTC](https://forum.choiceofgames.com/t/averaging-stats-together/1960/8 "2013-12-09T19:08:44Z")

</div>

@andymwhy Just like so:

Set bridge\_integrity round((((bridge\_left)+(bridge\_right))+(bridge\_middle))/3)

Note the extra parentheses to round the whole sum.

---

<div class="post-metadata">

**Author:** ![Havenstone](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/havenstone/32/198451_2.png) [@Havenstone](https://forum.choiceofgames.com/u/Havenstone)\
**Post date:** [December 10, 2013, 3:10am UTC](https://forum.choiceofgames.com/t/averaging-stats-together/1960/9 "2013-12-10T03:10:44Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Vendetta](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/vendetta/32/533_2.png) [@Vendetta](https://forum.choiceofgames.com/u/Vendetta)\
**Post date:** [December 10, 2013, 3:27am UTC](https://forum.choiceofgames.com/t/averaging-stats-together/1960/10 "2013-12-10T03:27:03Z")

</div>

@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!).
