# How to make stats variable depend on another stats variable?(with math operation)

**URL:** <https://forum.choiceofgames.com/t/how-to-make-stats-variable-depend-on-another-stats-variable-with-math-operation/117923>\
**Category:** ChoiceScript Help\
**Tags:** language, coder\
**Created:** [May 7, 2022, 12:30pm UTC](https://forum.choiceofgames.com/t/how-to-make-stats-variable-depend-on-another-stats-variable-with-math-operation/117923 "2022-05-07T12:30:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Apheos\_Suraka](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/apheos_suraka/32/168386_2.png) [@Apheos\_Suraka](https://forum.choiceofgames.com/u/Apheos_Suraka)\
**Post date:** [May 7, 2022, 12:30pm UTC](https://forum.choiceofgames.com/t/how-to-make-stats-variable-depend-on-another-stats-variable-with-math-operation/117923/1 "2022-05-07T12:30:43Z")

</div>

As you can see in the picture, i have these main stats and the sub stats

the main stats should affect the sub stats whenever it changes  
ex: if i upgrade the “phys” main stats from 0 to 5, the “max\_life” sub stats will also rise from 0 to [main stat “phys” x3]

anyone have an idea how do i do this?

![image](https://global.discourse-cdn.com/choiceofgames/original/3X/f/5/f5d9729ef7f1060f78e165f8004f3b28539f0d68.png)

---

<div class="post-metadata">

**Author:** ![Loudbeat](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/loudbeat/32/115975_2.png) [@Loudbeat](https://forum.choiceofgames.com/u/Loudbeat)\
**Post date:** [May 7, 2022, 12:36pm UTC](https://forum.choiceofgames.com/t/how-to-make-stats-variable-depend-on-another-stats-variable-with-math-operation/117923/2 "2022-05-07T12:36:20Z")

</div>

```nohighlight
*set phys +5
*set max_life (phys*3)

```

Have you tried something like that?

---

<div class="post-metadata">

**Author:** ![Apheos\_Suraka](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/apheos_suraka/32/168386_2.png) [@Apheos\_Suraka](https://forum.choiceofgames.com/u/Apheos_Suraka)\
**Post date:** [May 7, 2022, 1:30pm UTC](https://forum.choiceofgames.com/t/how-to-make-stats-variable-depend-on-another-stats-variable-with-math-operation/117923/3 "2022-05-07T13:30:46Z")

</div>

if i put it in the startup file will it always automatically work whenever the main stat change or i have to put this code every time the stat changes?

---

<div class="post-metadata">

**Author:** ![nocturno](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/nocturno/32/146868_2.png) [@nocturno](https://forum.choiceofgames.com/u/nocturno)\
**Post date:** [May 7, 2022, 1:49pm UTC](https://forum.choiceofgames.com/t/how-to-make-stats-variable-depend-on-another-stats-variable-with-math-operation/117923/4 "2022-05-07T13:49:35Z")

</div>

I would put those two \*set commands in a subroutine/label which I would call whenever necessary. The value to increment would be a parameter of that function.

---

<div class="post-metadata">

**Author:** ![Loudbeat](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/loudbeat/32/115975_2.png) [@Loudbeat](https://forum.choiceofgames.com/u/Loudbeat)\
**Post date:** [May 7, 2022, 2:14pm UTC](https://forum.choiceofgames.com/t/how-to-make-stats-variable-depend-on-another-stats-variable-with-math-operation/117923/5 "2022-05-07T14:14:41Z")

</div>

Both the options would work, with the individual command each time you modify the main one, and on a sub routine you’ll also call whenever you modify the main variable. As far as I know choicescript doesn’t have a background running checking for the variables so you have to do it manually one way or the other.

---

<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:** [May 8, 2022, 2:15pm UTC](https://forum.choiceofgames.com/t/how-to-make-stats-variable-depend-on-another-stats-variable-with-math-operation/117923/6 "2022-05-08T14:15:29Z")

</div>

Closed on May 8, 2022, 2:15pm UTC

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