# Help with stats

**URL:** <https://forum.choiceofgames.com/t/help-with-stats/163802>\
**Category:** ChoiceScript Help\
**Tags:** coder\
**Created:** [January 8, 2025, 3:38pm UTC](https://forum.choiceofgames.com/t/help-with-stats/163802 "2025-01-08T15:38:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daring\_Knight](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/daring_knight/32/242964_2.png) [@Daring\_Knight](https://forum.choiceofgames.com/u/Daring_Knight)\
**Post date:** [January 8, 2025, 3:38pm UTC](https://forum.choiceofgames.com/t/help-with-stats/163802/1 "2025-01-08T15:38:30Z")

</div>

Hey y’all. I was wondering if it was possible to connect different variables to each other. Say, if I have three different variables for the mcs army (morale, discipline, and stamina) but I want to express the overall condition using just one variable like army strength so an increase in morale will result in a proportional increase in army strength without me having to write “\*set armystrength-10” and I can also be able to reduce the strength and cause a decrease in the other three stats as well. Is there a way to do it or do I have to do the changes manually?

---

<div class="post-metadata">

**Author:** ![cup\_half\_empty](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cup_half_empty/32/273983_2.png) [@cup\_half\_empty](https://forum.choiceofgames.com/u/cup_half_empty)\
**Post date:** [January 8, 2025, 4:13pm UTC](https://forum.choiceofgames.com/t/help-with-stats/163802/2 "2025-01-08T16:13:27Z")

</div>

You have to define what’s the relationship between these variables and `army_strength`. Is `army_strength` the average, the sum, or something else?

To keep the values in sync, every time you update one of the base values, you’ll have to update army\_strength as well. There’s no way to do that automatically.

On the other hand, if you’re only going to use the derived value in the stats screen, you can do the calculation right there, so whenever the player opens the stats, army\_strength will be up to date. Otherwise, I’m afraid, you’ll have to do it manually.

---

<div class="post-metadata">

**Author:** ![Daring\_Knight](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/daring_knight/32/242964_2.png) [@Daring\_Knight](https://forum.choiceofgames.com/u/Daring_Knight)\
**Post date:** [January 8, 2025, 5:11pm UTC](https://forum.choiceofgames.com/t/help-with-stats/163802/3 "2025-01-08T17:11:50Z")

</div>

Ah, I see. At least I don’t feel stupid for doing it manually all this time 😅

---

<div class="post-metadata">

**Author:** ![Speedcubing\_Gaming](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/speedcubing_gaming/32/208120_2.png) [@Speedcubing\_Gaming](https://forum.choiceofgames.com/u/Speedcubing_Gaming)\
**Post date:** [January 9, 2025, 6:12am UTC](https://forum.choiceofgames.com/t/help-with-stats/163802/4 "2025-01-09T06:12:00Z")

</div>

There is an alternative to updating everything manually. That is to make a subroutine or scene dedicated to performing updates and whatnot that are always calculated the same way. Here is the minimum working example:

> **startup.txt**
>
> ```choicescript
> *comment startup.txt
> *title Help With Stats
> *author J. S. Fung
> *scene_list
> startup
> chapter1
> 
> *create army_strength 50
> *create army_morale 50 
> *create army_discipline 50 
> *create army_stamina 50
> 
> Here we assume army_strength is:
> 
> 30% army_morale
> 
> 30% army_discipline
> 
> 40% army_stamina
> 
> *finish
> 
> ```

> **chapter1.txt**
>
> ```choicescript
> *comment chapter1.txt
> 
> *temp change 0
> 
> *label stat_change
> 
> army_strength: ${army_strength}
> 
> army_morale: ${army_morale}
> 
> army_discipline: ${army_discipline}
> 
> army_stamina: ${army_stamina}
> 
> *choice
> #Update army strength.
> Current army_strength: ${army_strength}
>     
> Enter the decrease in army strength (negative numbers only).
> [i](This can also be set in code instead)[/i]
> *input_number change (0 - army_strength) 0
> *gosub_scene subroutines decrease_armystrength change
> *goto stat_change
> #Update morale.
> Current army_morale: ${army_morale}
>     
> Enter the army morale.
> [i](This can also be set in code instead)[/i]
> *input_number army_morale 0 100
> *gosub_scene subroutines calc_armystrength
> *goto stat_change
> #Update discipline.
> Current army_discipline: ${army_discipline}
>     
> Enter the army discipline.
> [i](This can also be set in code instead)[/i]
> *input_number army_discipline 0 100
> *gosub_scene subroutines calc_armystrength
> *goto stat_change
> #Update stamina.
> Current army_stamina: ${army_stamina}
>     
> Enter the army stamina.
> [i](This can also be set in code instead)[/i]
> *input_number army_stamina 0 100
> *gosub_scene subroutines calc_armystrength
> *goto stat_change
> #End
> *goto continue
> 
> *label continue
> This concludes the test.
> 
> *finish
> 
> ```

> **subroutines.txt**
>
> ```choicescript
> *comment subroutines.txt
> 
> *label calc_armystrength
> *comment change to match your formulation
> *set army_strength (((0.3*army_morale) + (0.3*army_discipline)) + (0.4*army_stamina))
> *return
> 
> *label decrease_armystrength
> *params strength_change
> *temp strength_percent (strength_change / army_strength)
> *set army_morale + (army_morale * strength_percent)
> *set army_discipline + (army_discipline * strength_percent)
> *set army_stamina + (army_stamina * strength_percent)
> *set army_strength + strength_change
> *return
> 
> ```

Below are some screenshots of the example being tested.

> **Screenshots**
>
> ![image](https://global.discourse-cdn.com/choiceofgames/original/3X/0/3/03503827742b86f905bd9b6e600536f46210864e.png)  
> ![image](https://global.discourse-cdn.com/choiceofgames/original/3X/e/e/ee79716949c618dee65c0c855765ebd0881ecc12.png)  
> ![image](https://global.discourse-cdn.com/choiceofgames/original/3X/8/7/8730f0c1e9231508d3169ea432cee2ed90c1aa0a.png)  
> ![image](https://global.discourse-cdn.com/choiceofgames/original/3X/f/6/f695528f575a1b46355c4495d5c63dcc7ae4caef.png)  
> ![image](https://global.discourse-cdn.com/choiceofgames/original/3X/a/4/a4eab9f1787ca70571d9b46323048d911f2bfa94.png)  
> ![image](https://global.discourse-cdn.com/choiceofgames/original/3X/0/f/0f59444a1c1c4a8c894f9eded8f8b09e20d3f329.png)  
> ![image](https://global.discourse-cdn.com/choiceofgames/original/3X/4/b/4b941c82ce933660d2cb2b86ac40d552c7a1ce37.png)  
> ![image](https://global.discourse-cdn.com/choiceofgames/original/3X/8/b/8bcd9fea97106ac0b0581b084638bfbbb2cd9f5e.png)

---

<div class="post-metadata">

**Author:** ![Daring\_Knight](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/daring_knight/32/242964_2.png) [@Daring\_Knight](https://forum.choiceofgames.com/u/Daring_Knight)\
**Post date:** [January 9, 2025, 6:17pm UTC](https://forum.choiceofgames.com/t/help-with-stats/163802/5 "2025-01-09T18:17:10Z")

</div>

Thanks. I had no idea you could do this

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/choiceofgames/original/3X/e/f/efe1497a762edecdb6d569a1c4abee87508bf002.png) [@system](https://forum.choiceofgames.com/u/system)\
**Post date:** [January 10, 2025, 6:18pm UTC](https://forum.choiceofgames.com/t/help-with-stats/163802/6 "2025-01-10T18:18:09Z")

</div>

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.
