We will now continue the script programming by building upon the first room.
By default, SCI Studio uses the naming system rmXXX for rooms, so the first room is naturally rm001. You could name them anything you like, but this naming system works the best. Sierra used it as well.
In the Game Explorer, there's a list of the game's resources.
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 read the "rm001" script. Double click on it, and the script editor will open up. |
Start by scrolling down to the rm001 instance. It is the first instance in the script. This too, can be named anything you wish, but it only makes sense to name it the same name as the script.
The properties specify the characteristics of your room.
|
In each room, you'll want the ego to be at a certain position on the screen. To handle this, there is a switch statement at the top of the room instance's init() method. This can be used to check the room that the ego has come from. For example, if the ego came from the west room, you'll want to position in on the left side of the screen. You can put in cases for any or all of the four surrounding rooms. At the end of it is the default case, so if the room the ego has come from doesn't match any of the cases, the default is executed. When starting the game, the default case will be executed since the ego hasn't been in any other rooms. This being the case, it is where you will set up the coordinates for the ego when the game is started.
Scroll down to the send to gEgo. This code tells the interpreter to position ego at 150 pixels from the left and 130 pixels from the top. It then tells the interpreter to set the ego's loop to loop #1, which is ego facing left. You can change these values. Just remember that the X coordinate must be from 0 to 319, the Y must be from 0 to 189, and the loop must be from 0 to 3. |
Click the "Compile and Run" button and you will see the actor is now part of your game! |
Your game will now look something like this:
Each room consists of two main instances: a public Rm instance and a local Script instance.
When the game changes to a new room, it calls the Rm instance's init() method. In this case, it's rm001's init() method. This method is executed only once, and used to set things up. The init() method sets up the room's script as the RoomScript instance. As soon as the Rm's init() method is done, your room becomes controlled by the RoomScript instance. The rm001 is just used for initialization.
The RoomScript instance is used to handle and perform all the room's events. There are three methods which you can have in it: the doit() method, the handleEvent() method, and the changeState() method. Some rooms may not need any of these, while some others may use all of them.
The RoomScript Methodsdoit |
If your RoomScript has a doit method, it's code will be executed repeatedly, once per interpreter cycle. How many times per second it is called depends on the speed the game is set to.
|
||
handleEvent |
The handleEvent method is the most important method for rooms. It handles the input from the user, including the text that they enter in the "Enter Input" dialog. This is where you check what they input and perform the the tasks complementary to it.
|
||
changeState |
The changeState method is similar to the doit method, but it is only executed if your set it up to be. This can be used in any room, but it primarily used on the title screen. For example, you can use this to draw a view, then move it for 3 seconds, then play a sound for 5 seconds, then draw a different view, then animate it for 8 seconds, then wait for 10 seconds, then go to another screen, etc. You can use this for absolutely anything you want. Each RoomScript instance has state and cycles properties.
The actual time in seconds of the cycles varies depending on the game speed. With the game speed set to 1, 60 cycles equals about one second. However, if the speed was set to 2 for example, 30 cycles would be about one second. The default speed gives about 10 cycles per second. You should never set the game speed to 0 when doing timed animation, as it will remove the cycle delay, which will give unpredictable speeds from computer to computer.
|
That concludes the RoomScript instance. In the next chapter, you will learn all about handling the user's "Said" input.
Top
You can help keep The Sierra Help Pages and its affiliates alive by helping to defray some of the costs of hosting this site. If it has been of help to you, please consider contributing to help keep it online.Thank you.
The Sierra Help Pages | Sierra Game Help | Walkthroughs | Hints, Tips & Spoilers | Utilities | Links | SHP Forums | Search
© 2013 to present The Sierra Help Pages. All rights reserved. All Sierra games, artwork and music © Sierra.