Suicide in I7

Hi, I’m fairly new to developing IF and very new to Inform. In one of my games, I want to give the player the option to commit suicide, as this was a much-requested feature during testing. It should print a short description of what they’ve just done, and then end the game in death.

I know that I can set “suicide” as a verb, or tell it instead of “killing self” or “killing me” or what have you, to perform the desired action… but is there a simpler way than thinking of every possible way the player could phrase the desire to end the character’s life and setting it up individually?

Thanks in advance for your help. =)

No, you pretty much have to think of all the different ways. However you only have to do this once, and then you could use it for all your games, or give the code to friends for their games.

However you can get around some of the work by using the shortcuts that Inform provides. For example, say you want to let the player kill themself with any object they can hold in their inventory. Rather than typing ‘understand “kill myself with ball”’, ‘understand “kill myself with knife”’, ‘understand “kill myself with matches”’, etcetera, you can use the text tokens which Inform will substitute for – in this case, ‘understand “kill myself with [something preferably held]”’. The added benefit is that when you add a new object, you don’t have to add new code to take care of this new case. It’s good to think of much of your code in this way, to make it flexible for new cases that may come up, though you don’t need to go too crazy to make it absolutely flexible.

See the Understanding section in the manual for more on this, section 16.4.

Thanks, George. I like your suggestion about setting up a flexible way to have the player commit suicide with any held object, and will probably use it in future games. This one, however, doesn’t contain much in the way of potential weapons… and I think my target audience will find using their bare hands funnier anyway.

Hmm. I guess I have a morbid target audience.

Here’s what I ended up using. It probably isn’t the most efficient way to do it, but it seems to work all right. This won’t work for killing oneself with a specific item.

[code]Killing is an action applying to one thing. Understand “kill [something]” as killing. Instead of killing the player: say "(Insert how you want to player to die here… I didn’t include mine as it’s pretty gruesome).

Way to take the easy way out."; end the game in death.

Check killing: if the noun is not the player then say “Violence isn’t the answer to this one.”

Suiciding is an action applying to nothing. Understand “commit suicide” as suiciding. Understand “suicide” as suiciding. Instead of suiciding, try killing the player.[/code]

The only problem I have right now is that punching yourself also results in suicide. It’s probably not a likely thing for the player to type, but it isn’t exactly accurate either. If anybody has refinements, I’m open to suggestions.

Yeah, attack, kill, punch, they’re all synonyms for the same action in Inform (namely attack). You can see all this under the Index/Actions tab. I think the trick is to clear the punch command with 'Understand the command “punch” as something new", and then write your own rule for it.

You don’t need to define a new action “killing”, since all you’re doing here is making all the ways to say “kill [something]” point to your new killing action. You can just use:

[code]Instead of attacking the player: say "(Insert how you want to player to die here… I didn’t include mine as it’s pretty gruesome).

Way to take the easy way out."; end the game in death.

Suiciding is an action applying to nothing. Understand “commit suicide” as suiciding. Understand “suicide” as suiciding. Understand the command “die” as something new. Understand “die” as suiciding. Instead of suiciding, try attacking the player.[/code]
(I added the lines for “die”, since by default typing DIE tries to quit the game. If you don’t want them, you can take them out again.)

If you want to only allow the player to use words like “kill” to kill him/herself, as opposed to words like “punch”, “kick”, “crack”, it’s a little more complicated, but you can do it like this:

[code]Killing is an action applying to one thing.
Understand the command “kill” as something new.
Understand “kill [something]” as killing.
Understand the commands “attack” and “destroy” and “murder” as something new.
Understand the commands “attack” and “destroy” and “murder” as “kill”.
Instead of killing the player: say "(Insert how you want to player to die here… I didn’t include mine as it’s pretty gruesome).

Way to take the easy way out."; end the game in death.

[This lets you attack other things as usual.]
Carry out killing:
try attacking the noun instead.

Suiciding is an action applying to nothing. Understand “commit suicide” as suiciding. Understand “suicide” as suiciding. Understand the command “die” as something new. Understand “die” as suiciding. Instead of suiciding, try killing the player.[/code]
This means you have to list all the vocabulary for killing, which you didn’t want to do. But if you want to treat different kinds of attacks differently, you’ll have to.