SCI Studio Tutorial Chapter 23 - Using The Death Handler

From SCI Wiki
Jump to navigationJump to search

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.

Controls-DeathAddIcon.png

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.

Script Folder

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.


rm001

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:

Code:
(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:

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.

  • Next, we set the death dialog's view to 3, since that is the number we added it to the game as. To do this, you simply set it's caller property to to view number.
  • We then set the register property to the message we want to display in the death dialog.
  • Finally, we call the game's setScript() method with the dyingScript variable.

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!

 

< Previous: Chapter 22 - Handling The Player's ScoreNext: Chapter 24 - Using The Print Procedures >