Creating a maximum attribute

I’m having trouble with setting a maximum attribute that cannot be exceeded, this is coming up in the following context:

A character can have a maximum stamina of 24, luck of 12 and skill of 12 and these are set at the start of the game .They cannot max out stats at the start (code attached last for clarity)

The player can lose stamina through being hurt, attacked etc and then regain this by eg eating a provision , or pick up a lucky item or increase their skill

However, if the character eg eats some provisions and I use the code of
*set stamina + 7

then they can exceed the maximum limit

for example, they can be on stamina of 18, eat provision and go to stamina 25

Is there a way to set an attribute so it cannot be exceeded?

Here is the code for the game start, it works, it is here for more context:

*label init 
*temp ap 6
*temp skill_limit 4 
*temp stamina_limit 6 
*temp luck_limit 4 
*temp skillset false
*temp luckset false
*temp staminaset false
*label choose_stats 
You have ${ap} AP left to spend to increase your stats. Which stat do you want to increase
	*selectable_if (skillset = false) #Skill
		How many AP will you spend to increase skill? (1 - ${skill_limit}) 
		*input_number stat1 1 skill_limit 
		*set skill +stat1 
		*set skillset true
		*goto adjust_ap
	*selectable_if (staminaset = false) #Stamina
		How many AP will you spend to increase stamina? (1 - ${stamina_limit}) 
		*input_number stat1 1 stamina_limit 
		*set stamina +stat1
		*set staminaset true
		*goto adjust_ap 
	*selectable_if (luckset = false) #Luck
		How many AP will you spend to increase luck? (1 - ${luck_limit})
		*input_number stat1 1 luck_limit 
		*set luck +stat1
		*set luckset true
		*goto adjust_ap 
	#I'm finished spending AP 
		*goto done
	#Reset stats and AP
		*set stamina 17
		*set luck 8
		*set skill 8
		*goto init 
*label adjust_ap 
*set ap -stat1 
*if ap < 1 
	*goto done
*if skill_limit > ap
	*set skill_limit ap
*if stamina_limit > ap 
	*set stamina_limit ap
*if luck_limit > ap
	*set luck_limit ap 
*goto choose_stats 
*label done 
*goto_scene provisionstest

For the specific scenario you describe, checking manually for each addition is pretty much the only way, unless you can adapt the stamina system to fairmath.

  1. Create a max_stamina variable.
  2. After choosing stats, set it as current stamina:
*label done
*set max_stamina stamina
  1. When increasing stamina, either do this:
You sleep like a baby and recover all your stamina.
*set stamina max_stamina

Or create a subroutine to check for too much stamina:

You eat an egg and recover some of your stamina.
*set stamina + 7
*gosub limit_stats
You are ready to go.
*goto whatever
*label limit_stats
*if stamina > max_stamina
    *set stamina max_stamina

Or change stats to use fairmath, like the previous commenter suggested.


Amazing both, thanks!
Will try this next weekend now , fingers crossed :grinning:


This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.