From room to room and back

Hi, all!

Before starting on my "real" game, I am working on another simpler one which I use as a benchmark to find out how to cope with a number of "standard" situations. So, right now I am having this problem:

The player is in room A and he wants to go to room B. Naturally he clicks on the exit that goes from A to B.

At this moment (I deal with what follows in the "On Enter" script for room B) a NPC shouts "Hey, don't go there!". The player prefers to desist, and so I put him back in room A. (End of script)
And then room A's description is displayed twice. How can I avoid that? Actually I would prefer the description not to be displayed at all. Once would be OK (I have a workaround) but certainly not twice. Twice spoils everything.

This is what's happening:

Player leaves A.

Player enters B, then is turned around immediately and:

Player enters A.

When a player enters A, it is Quest's job to show the room description, and it does its job well!

You can set a script on the exit from A to B, which actually keeps the player from leaving A.

This is one of the issues with exit/enter scripts. The player object's changedparent script runs every time a player is moved to a different room; and runs the exit scripts for the old room, the before enter script, the room description, and the enter script. If one of those scripts moves the player again, another copy of the changedparent script runs (displaying the description for room A), and then the first instance runs again.

There are a few relatively simple ways to get around this.

Method 0: Probably the best option

Don't move the player. On the exit from room A to room B, tick the box that says "Run a script (instead of moving the player automatically)".

Have the NPC shout a message to the player and persuade them not to go to room B.

This doesn't display the description because the player stays in room A, rather than moving and then being moved back.

Note that the script runs instead of the player going to the other room. So if there's a situation where the player can actually go there later (maybe the NPC isn't there, or something?), the script will need to check for that and move them to room B yourself..

Method 1: Prevent the description showing twice

You can temporarily turn off room descriptions, so that the second time the player is moved, the description isn't shown.

game.showdescriptiononenter = false
MoveObject (player, Room A)
game.showdescriptiononenter = true

Note that this will still run exit scripts for room B and enter scripts for room A, just won't show the description again.

Method 2: Prevent the changedparent script from running

This will prevent both the description and room A's "enter" scripts from running twice.

player.changedparent = null
MoveObject (player, Room A)
player.changedparent = this.changedparent

(This will work as long as the room doesn't have a custom changedparent script for some reason. By default, all objects have a changedparent script that is run automatically when they are moved; which check if the object is the player, and if so runs the various enter/exit scripts. So deleting that script from the actual player object and copying it back afterwards from another object works fine)

Method 3: Prevent the description from showing at all

We disable the room descriptions, and enable them again at the end of the turn.

game.showdescriptiononenter = false
MoveObject (player, Room A)
SetTurnTimeout(0) {
  game.showdescriptiononenter = true

(Haven't tested this, but looking at the core code I think it should work)

Seems these will work. What about a ClearScreen at some point. perhaps OnRoomEnter script of room A? I've never had this happen. I have the 'ClearScreen when player enters a room' ticked on the Room description feature of the game, because the old scrolled text of an old room is no longer pertinate.

The workaround in gamebook mode (not helpful to you, but for any gamebook folks reading this years from now) is to just make another page (room) that replicates the original room (page) but just has the NPC yelling "don't go in there!" as the text. But really you're just in room (page) 1b.


mrangel's plans look solid.

Another option is to lock the door. Then, under "print message when locked" put in the NPC's dialogue. Locking is a mechanic within the game that makes it so a player can't exit. Functionally, anything can be a key that unlocks the door, including an action by the player. For instance, if you don't want the player to leave unless they have read a book, once they read the book, have the game internally unlock the door. The next time they try to leave, the player will be able to exit into the next room.

Log in to post a reply.