Powering the Puzzle
Implementing the shelf is fairly simple. With most of the steps involving bringing up a dialog bubble, I decided to simplify the task by taking the three lines of code that is required to set up the message and converting it into a single function call. Actually, because there is a case where a special message code is required, I wrote the following two functions to handle the poping up of the dialog. The dialog event handler (not shown) hides the dialog bubble when a dialog button is pressed.
- function showMessage(smes)
- {
- thought_movie._visible = true;
- thought_movie.ST.setMessage(smes);
- thought_movie.ST.setMenu(2,"Continue", O16MG_MESSAGEHIDE);
- }
- function showEventMessage(smes, mcode)
- {
- thought_movie._visible = true;
- thought_movie.ST.setMessage(smes);
- thought_movie.ST.setMenu(2,"Continue", mcode);
- }
The shelf is actually implemented using a switch statement based on the current state of the inventory box. This state reflects what item, if any, that the player is attempting to use on the shelf. Each object can only be used if the shelf is in a particular state so the shelf state is often used to determine if the shelf state is going to be changed and which message to bring to the player.
- function shelfAction()
- {
- sstate = ootw16_shelfState;
- istate = inv_movie.getInventoryMode();
- trace ("Shelf state is " + sstate);
- trace ("inventory state is " + istate);
- switch (istate) {
- case O16INV_STATENORMAL :
- if (sstate == O16SHELF_NOPOWERGPS) {
- showMessage("Wow, a GPS device. Now I can find out where I am...well I could find out where I am if the battery wasn’t dead. To bad I don’t have some type of battery.");
- ootw16_shelfState = O16SHELF_EMPTY;
- } else if (sstate == O16SHELF_EMPTY) {
- showMessage("Not sure why Charles would have a shelf in his plane, but this shelf here would be an ideal work space if I wanted to build something. What would I want to build?");
- } else {
- showMessage("Why would I pick it up when I am not finished putting it together?");
- }
- break;
- case O16INV_STATEKEY :
- trace("Using key which should no longer be in inventory error!");
- // treat this error like using the orange hence no break statement
- case O16INV_STATEORANGE :
- if (sstate >= O16SHELF_ORANGE) {
- showMessage("I don’t think that I need to use more than one orange for this.");
- } else if (sstate == O16SHELF_EMPTY) {
- showMessage("This would be a good item to start with.");
- ootw16_shelfState = O16SHELF_ORANGE;
- } else {
- showMessage ("There already is something on the shelf");
- }
- break;
- case O16INV_STATEALUMINUM :
- if (sstate == O16SHELF_ORANGE) {
- showMessage ("I'm half way there!");
- ootw16_shelfState = O16SHELF_ORANGEALUM;
- ootw16_usedDebris = true;
- } else if (sstate == O16SHELF_ORANGECOPPER) {
- showMessage("A low power battery. But does it have enough juice?");
- ootw16_shelfState = O16SHELF_ORANGEBATTERY;
- ootw16_usedDebris = true;
- } else {
- showMessage(TIRED_MESSAGE);
- }
- break;
- case O16INV_COPPER :
- if (sstate == O16SHELF_ORANGE) {
- ootw16_usedWire = true;
- ootw16_shelfState = O16SHELF_ORANGECOPPER;
- showMessage ("I'm half way there!");
- } else if (sstate == O16SHELF_ORANGEALUM) {
- showMessage("A low power battery. But does it have enough juice?");
- ootw16_usedWire = true;
- ootw16_shelfState = O16SHELF_ORANGEBATTERY;
- } else {
- showMessage(TIRED_MESSAGE);
- }
- break;
- case O16INV_GPS :
- if (sstate == O16SHELF_ORANGEBATTERY) {
- showEventMessage("Wow it works. Hey, I’m on a small island right near the mainland. It should be easy to get back home. But it is getting dark out and I am rather tired. This cockpit is probably the best place to get some sleep.", O16MG_GAMEOVER);
- ootw16_shelfState = O16SHELF_FINALGPS;
- } else {
- showMessage(TIRED_MESSAGE);
- }
- }
- gotoAndPlay("Cockpit");
- }