End game before player enters room

Novlaux
22 Jan 2020, 22:50

I have an event set up so that if a player enters a room and does not have a certain item, then their health should reduce to 0 and the game ends. But whenever I try to test, it still shows the description of the next room before the player dies and game over.

I want to know a way to trigger a conditional branch before entering a room, and if they fail, the game ends right there, before the next rooms info displays.

I am using the “Before enter room” tab on the room they are entering into.


mrangel
22 Jan 2020, 23:35

OK; "before enter room" will run after the player moves into the room, but before displaying the room description. However, the room description will still show even if the player is dead; once the script is started, it keeps on going.

There are two obvious ways to do this:

  1. Exit script

Put a script on the exit that leads into the room. This script runs instead of moving the player, so you could make it something like:

if (Got (some object)) {
  player.parent = this.to
}
else {
  msg ("Rocks fall, you die.")
  player.health = 0
}

This means that if they don't have the item, they die without actually entering the room.

  1. Using the room's "before enter" script

You've tried this already. But the script runs before the player enters the room; after it runs, the player will continue entering the room even if they're dead.

So there's 2 things you can do. In both cases, your script needs to do something else immediately after (or before) killing the player.
The most obvious is to move the player out of the room again, so that the description doesn't display. You could move them to a room whose name is "dead" and prefix is "You are". So instead of "You are in [room name]", it says "You are dead". And because the dead room has no description, no objects, and no exits, nothing else is displayed. A lot of people make use of this, and the main downside is that it will run the "on exit" script for the room they never really entered.

Or, you can simply turn off room descriptions after the player dies, by adding the line:

game.showdescriptiononenter = false

This flag hides room descriptions until the player uses the "look" command; which they can't do because they're dead.


Novlaux
25 Jan 2020, 05:27

Thank you very much, that answers my question completely.