Making a variable based on another variable

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.

3 Likes

*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.

5 Likes

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!

3 Likes