# Help with choice script math

Can i do this in choice script? Because i don’t think i can and in my game, the player’s HP is based on their constitution and it constatly changes.

`````` *set HP 10 + (2 * \${constitution})
*set MP 10 + (2 * \${intelligence})

``````

yes, but ditch the \${} surrounding the variables. Also you need to update HP and MP everytime the variables that depend on them change.

i don’t understand

``````*set HP 10 + (2 * constitution)
*set MP 10 + (2 * intelligence)
``````

Also, when you increase your constitution and intelligence, the HP and MP won’t increase if you don’t set them again.

So, for example. If at the start of the scene, your constitution is 10 and you run this

`*set HP 10 + (2 * constitution)`

then your HP will be 30.

If further in the game you increase your constitution to 15

`*set constitution 15`

then your HP will remain at 30. To update it, you have to set the HP again

`*set HP 10 + (2 * constitution)`

To avoid copy-pasting code, you can add that to a subroutine and call it when you need.

``````*label update_hp

*set HP 10 + (2 * constitution)

*return
``````
``````*set constitution 15
*gosub update_hp
``````

Using a subroutine has the advantage of allowing you to make a change in a single place in case you want to change the scaling of the hp with (using 3 instead of 2 for example). If you would copy and paste it every time there is an update, you will have to hunt every instance in your code, and in will take more time and will cause bugs if you forget to update one of them.

You can even compact the method further by passing the new constitution as a parameter.

``````*label update_constitution
*params new_con

*set constitution new_con
*set HP 10 + (2 * constitution)

*return
``````

And when then you write only a single line of code when you want to increase the constitution without worrying about updating the HP

`*gosub update_constitution 15`

3 Likes

thank you

1 Like

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