Stats that kill you?

Hi everyone!
I’m fairly new to this whole Choice Script so please bear with me.
I’ve been thinking about trying to make a horror game and I wanted to have one (or maybe more?) stat that ends the game when it reaches a “critical” number. Like, HP/blood loss, or maybe even fear…
How would you do this?
I mean, I’m assuming it involves some *if statements but how and where would one put this in the code?

Thank you in advance for your replies!

I hope this can help!

1 Like

You would need to check the variable(s) everytime they changed. Either directly or using a subroutine like @N1GHTMAR3 suggest. :blush:

1 Like

I was reading about subroutines last night but it didn’t occur to me that it would be the answer to my question! Thanks, I’ll give that a try!

Here’s a simple example…
Your character has HP.
If the character’s HP goes to 0 or below, the character dies.
An if statement to handle this might look something like…

*if myHP <= 0
 *goto_scene death

So that means… if my HP is less than or equal to 0, we will go to a scene called death.
You don’t have to go to another scene. You can also use *goto
You can also have the character resurrect from a given point.
The limits are your imagination. It’s up to you.

2 Likes

But I would still need to check that stat every time it changes, right? Isn’t there a way to write a piece of code that does that automatically without having to manually copy and paste that everywhere?

You could use a gosub, then you would only need to write

*gosub (labelname)

If you are using it in more than one scene, you should use *gosub_scene instead, so you only need to write the subroutine once, and not for every scene.

1 Like

Yes, it’s quite possible. This is the creation of a *gosub
You might modify the code to look like this:

*label checkHP
*if myHP <= 0
 *goto_scene death
*return

You can go to this code by doing a *gosub
Specifically:

*gosub checkHP

You can name the piece of code whatever you want, but you have to then be consistent with the naming.
In other words, if you had *label helloworld then you would have to *gosub helloworld.
The *return command is important because it tells a *gosub when to go back to where it was.

1 Like

This is very helpful, thanks!
I did some research on gosub and I think I figured out how it works now. Thank you guys!!

1 Like

*params

:open_mouth: ~~

Coming a bit late to this thread but I thought I’d mention what I do in these situations.

I use *gosub with parameters to handle all the work associated with stats. I pass the stat and the amount to the subroutine which then takes care of adding or subtracting to/from the specified stat, it handles the boundaries for the stat (ensuring it can’t go above or below predefined values) and it prints an optional DEBUG statement showing the stat change. Having all that in one place makes debugging a lot easier and reduces the amount of work involved, in the longer term anyway. My philosophy is to use subroutes for anything that involves tasks that are done repeatedly, especially if from many different places in the script.

I’m also writing a horror piece. I’m not going to have a total defeat, in the form of death, in mine though, I hate working through a story only to be killed at the end… unless it’s part of a resurrection routine of course! I’ll have various degrees of beligerence leading the ‘victim’ to turn the tables on his captors… or not… depending on how the player handles the character.

2 Likes