Chapter 23: Using The Death Handler

We've all played adventure games, only to find ourselves faced with the "Restore" "Restart" "Quit" dialog. Well, you'll probably need one in your game as well. They are very easy to implement, and are discussed fully here.

Getting Started

First you need to add the icon for the death dialog to your game. Open the game and the Resource Explorer will load.

Click on the "Resource" menu and select "Add Sample"->"View"->"Dead Icon". Save is as view #3.

Next you need to open the first room's script.

Click on the script folder and the list of scripts in your game will appear on the right, along with a preview of the first script.

Scroll down the list until you see the "rm001" script. Double click on it, and the script editor will open up with it.

Calling The Death Script

Now that the icon is part of the game, we can set the dialog up. First scroll down to the RoomScript instance's handleEvent method. Insert the line "(var dyingScript)" at the very top and it will look something like this:

(method (handleEvent pEvent)
  (var
dyingScript)
  (super:
handleEvent(pEvent))

This sets up a variable, in which we will store a pointer to the deathScript's instance.

Next, we will execute the death dialog. Scroll down to the end of the handleEvent and insert the following lines of code:

(if(Said('die'))
  =
dyingScript ScriptID(DYING_SCRIPT)
  (send
dyingScript:
    caller(3)
    register("You're dead dude! Thank you for playing \"Tutorial Quest\"!")
  )
  (send
gGame:setScript(dyingScript))
)

First this checks if they player typed "die". If they did, it obtains a handle to the dying script's instance.

Voila! You now have a death handler! The reason you can customize the icons and messages for the dialog is because you will probably have many difference scenarios, and will want the dialog to suit them accordingly.

The dialog waits three seconds, then displays your message and icon. Next, it displays the "Restore" "Restart" "Quit" dialog. The reason for this three seconds is so they player can see what's just happened before the dialog pops up. If you want to change it, you can modify the "dying" script.

That sums up the death handler! Next you will learn how to use the print procedures to print fancy dialog boxes!

<< Prev

Next >>