How to limit variables?

I’m having trouble with figuring out how to limit variables. I searched the wiki and the website for info. Essentially, I want to put limits on variables (stats) until certain conditions are met. What command would I use to add those limits? Any help is appreciated, thanks!

Limit them how? Like, what variables are in use? (That’s simple, just don’t use them.) Or what values they can have? (You’ll need to run a check every time you change them.)

You can use subroutines to achieve this goal. Instead of setting the variable directly, you will call the subroutine.

*temp power 1
*temp isStronk false

You approach a power stone.

*gosub increasePower 3

*label increasePower
*params extra_power

*if (isStronk)
    *set power + extra_power
    Power increased by {$extra_power}!
*else
    Lmao, get rekt! You are not stronk enough to become stronger.

*return

You can call this subroutine from any place inside the scene and it will go back to the place it was called from because of the return call. If you want to use these kinds of methods across multiple scenes, you can call *gosub_scene instead.

1 Like

For a slightly more practical example:

*label increasePower
*params extra_power

*set power + extra_power
*if (power > 10)
    *set power 10

*return

To set the upper limit at 10, in this case. For a more flexible subroutine the limit could be passed as second parameter.

What I mean is the player has points to spend to increase their stats and they can’t be increased until certain conditions are met.

Ah thanks! That helps, it gives me a few ideas

Cool! Thats a very useful approach, I might be able to implement that. I was more thinking they can increase for example strength to 100 pts but not past 100 until a condition is true. That approach is useful but how would I set numerical limits on how high a variable could get?