Is there a way to make "something" happen when a stat reaches 0?

Hi everyone! :slight_smile:
I’m writing my very first (hopefully) hosted game based on Monkey Island and Pirates of the Caribbean. :pirate_flag:
I have a question: is there a way to “make something happen” whenever in the story a chosen stat reaches 0?
Or should I check the stat EVERY time I modify it?
My ideal goal is finding a way, so WHENEVER in the story the chosen stat reaches 0, you go to a (bad) ending.

I hope I clearly explained myself, and I sincerely hope there is a way to accomplish what I’d like to do.
Thank you in advance for all your kind advice, your time, and your patience. :love_letter:

I think you’re thinking of *gosub

Oh wait. I’m not sure lol. But here’s a thread:

1 Like

Yes, you have to check the stat every time you modify it. ChoiceScript isn’t an event-driven language, there’s no way to automatically “fire” events like that.


You have to check the code every time you change it but it is possible to limit the actual code required by using the *gosub_scene command.

Quick question does the bad ending change depending on where in the story you are? Or is it the same ending?

1 Like

It can also be an *if statement mix with a goto…like

*if (stat1=0)
*goto_scene ending badending1

Somethink like that

*set variable_1 +1
*gosub_scene check_variables variable_1


(in scene check_variables)

*label variable_1

*if variable_1 >= 1
*some sort of command here
*other stuff if you need it
*even more stuff if you need it


This was basically the entire engine for my “increase the character’s age” subroutine in A Kiss from Death which checked if a character’s age was beyond a certain threshold in which case a scene would trigger to further the plot.

And yeah I had to gosub for each and every age increase in the entire game.

1 Like

Thank you, everybody. :love_letter:
I hoped there was an “easier” way to do that instead of checking every time.
I guess gosub will become my friend from now on.

1 Like

A bit of clever code can make it slightly easier.

For example the weapon choice in unnatural is only written once in a single scene which I used *gosub_scene weapon_choice whenever I want players to pick a gun.

I still have to send the player to the scene each time they have to choose a gun but using *gosub_scene allows me to only have to write out the gun code once but can send players to it every time I want.


Sorry I thought I already answered your previous question @Nocturnal_Stillness
If the stat reaches 0 the ending is the same. Thank you for your time and your advice