# Making a variable based on another variable

**URL:** <https://forum.choiceofgames.com/t/making-a-variable-based-on-another-variable/177081>\
**Category:** ChoiceScript Help\
**Tags:** coder\
**Created:** [April 25, 2026, 12:26pm UTC](https://forum.choiceofgames.com/t/making-a-variable-based-on-another-variable/177081 "2026-04-25T12:26:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_Great\_Michael](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@The\_Great\_Michael](https://forum.choiceofgames.com/u/The_Great_Michael)\
**Post date:** [April 25, 2026, 12:26pm UTC](https://forum.choiceofgames.com/t/making-a-variable-based-on-another-variable/177081/1 "2026-04-25T12:26:48Z")

</div>

Good day folks,

As some people may have read in other topics of mine im working on a combat system for a story of mine and I **almost** got everything to work like I want it to work with a single exception:

There are 2 variables in my game called “HP” and “max\_HP”  
You can probably take a guess what these 2 are for but here comes my question:

At the end of chapters I want the player to auto heal and the HP to be equal to max\_HP  
However I seem to struggle to figure out how to do so since testing so far has resluted in errors each time.  
Examples:

_\*set HP = max \_HP_  
Error: combat line 3: Invalid expression at char 4, expected NUMBER, STRING, VAR or PARENTHETICAL, was: EQUALITY [=]

_\*set (HP) = (max\_HP)_  
Error: combat line 3: Invalid expression; expected name, found OPEN\_PARENTHESIS at char 1

So im wondering, how exactly would I reset the players health after resting/healing etc. ?

On the topic of healing I also want to avoid the player to heal over the max\_HP  
I THINK that can be worked around with a \*_if_ statement.\*

\*if HP \> max\_HP\*  
\*_set HP = max\_HP_

But again I would first need a working command to make sure HP is set to max for that also to work.

---

<div class="post-metadata">

**Author:** ![ChanceOfFire](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/chanceoffire/32/270002_2.png) [@ChanceOfFire](https://forum.choiceofgames.com/u/ChanceOfFire)\
**Post date:** [April 25, 2026, 12:42pm UTC](https://forum.choiceofgames.com/t/making-a-variable-based-on-another-variable/177081/2 "2026-04-25T12:42:25Z")

</div>

`*set HP = max _HP`

There isn’t supposed to be an equal sign. Try

`*set HP max_HP`

General rule of thumb. =, \<, \> for \*if statements. +, - or just the value/variable for \*set statements.

Edit: Variables should not have a space between them. Make sure it is max\_HP and not max \_HP.

---

<div class="post-metadata">

**Author:** ![The\_Great\_Michael](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@The\_Great\_Michael](https://forum.choiceofgames.com/u/The_Great_Michael)\
**Post date:** [April 25, 2026, 1:17pm UTC](https://forum.choiceofgames.com/t/making-a-variable-based-on-another-variable/177081/3 "2026-04-25T13:17:19Z")

</div>

Sometimes the solution to a problem is much easier than you think.

I was under the assumption it needs some form of sign to understand that its 2 diffrent variables and not one but a space between is sufficient as I learned from you today.

Thank you I will try to remember this for futrue code.

Now the system actually works perfectly!

---

<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:** [April 26, 2026, 1:18pm UTC](https://forum.choiceofgames.com/t/making-a-variable-based-on-another-variable/177081/4 "2026-04-26T13:18:03Z")

</div>

Closed on April 26, 2026, 1:18pm UTC

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