Coding stamina reduction

I have stamina in my game, set to 50. The problem I’m running into is that when it comes to the player increasing their stats for the first time the stamina can dip into the negatives. I need the game to; move on after they don’t have enough stamina for another option, and leave them with left with whatever stamina they didn’t use.

My code looks like this:

*label train
You have the rest of the day to do whatever you want.
*choice
	#You could really use the practice. Train with the dummy. (Strength training)
		*set Strength +2
		*set Stamina -20
		*if Stamina >= 50
			You feel yourself getting tired. (Strength +2) (Stamina -20)
		*goto train
		*else
			*if Stamina <= 0 
				*goto endday1
	#I need to get faster. Run figure-eights between the dummy and the firepit. (Agility training)
		*set Agility +2
		*set Stamina -20
		*if Stamina >= 50
			Don't over due it. (Agility +2) (Stamina -20)
		*goto train
		*else
			*if Stamina <= 0
				*goto enday1
*label endday1

Just for clarification, is this how you indent your code?

*label train
You have the rest of the day to do whatever you want.
*choice
   #You could really use the practice. Train with the dummy. (Strength training)
      *set Strength +2
      *set Stamina -20
      *if Stamina >= 50
         You feel yourself getting tired. (Strength +2) (Stamina -20)
         *goto train
      *else
         *if Stamina <= 0
            *goto endday1
   #I need to get faster. Run figure-eights between the dummy and the firepit. (Agility training)
      *set Agility +2
      *set Stamina -20
      *if Stamina >= 50
         Don’t over due it. (Agility +2) (Stamina -20)
         *goto train
      *else
         *if Stamina <= 0
            *goto enday1
*label endday1

Sorry I didn’t double check the indents before I posted this, but yes.

I’m not an expert in ChoiceScript, but this seems like a math issue… so I’ll give it a shot.

Try checking Stamina against the minimum amount necessary to train. So try:
Stamina >= 20

This statement looks like it only ends the day when stamina is 0 or less. Try changing it to:
Stamina < 20

EDIT: To further clarify, if the day only ends when you have 0 or less stamina, it’ll let you train again even if your stamina is between 1 - 19. And any of those numbers - 20 will put you in the negative. My guess is that this is why you’ve been running into the negatives.

Try double checking your code. As Foiled mentioned, it’s impossible to get your stamina to negative if you make your first choice for the first time. Either you don’t have the stamina set to 50, or there’re other commands that reduce the stamina outside the code you’ve shown us.

Here’s the issue I’m seeing. You’ve coded it so that it only checks if your stamina is greater than 50 or less than 0. Everything else in-between gets ignored.

      *if Stamina >= 50
         You feel yourself getting tired. (Strength +2) (Stamina -20)
         *goto train
      *else
         *if Stamina <= 0
            *goto endday1

When the parser reads this, it’s going to check if your stamina is greater than 50, and if it’s not, it’s going to go to the *else, which will only check if your stamina is less than 0. If your stamina is 1-49, the game doesn’t do anything. That might be causing some looping issues that affect the stamina.

Try this code instead:

*label train
You have the rest of the day to do whatever you want.
*choice
  #You could really use the practice. Train with the dummy. (Strength training)
    *set strength +2
    *set stamina -20
    *gosub stamina_rounding
    *if stamina = 0
      *goto endday1
    *else
        You feel yourself getting tired. (Strength +2) (Stamina -20)
        *goto train

The gosub is:

*label stamina_rounding
*if stamina > 100
  *set stamina 100
  *return
*elseif stamina < 0
  *set stamina 0
  *return
*else
  *return

This code will run through the gosub after changing the stats to see if it exceeds the 0/100 limits and adjust accordingly. Then, if the stamina is at 0, it’ll end the day; otherwise, it’ll continue training.

The last issue I’m having now is in the test I’m getting an error saying “bad label stamina_rounding”

Either the label being called by the gosub/goto doesn’t exist, or more likely, the spelling doesn’t match. Make sure it’s spelled the same both where it’s defined in the label and where it’s called by the gosub.

1 Like

Please wrap any code you’re posting in ``` and ```.

It helps those who are trying to help you immensely. I’ve edited your post to do it for you this time.

1 Like

Ok, thank you. I’ll do this from now on.