Elevator and stairs (JACL example): Difference between revisions
From IFWiki
StuartAllen (talk | contribs) m (missing word in text.) |
StuartAllen (talk | contribs) m (Fixed bug.) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
The guy who did the Inform example wasn't wrong... | The guy who did the Inform example wasn't wrong... | ||
Line 6: | Line 4: | ||
#!../bin/jacl | #!../bin/jacl | ||
attribute OUTSIDE_LIFT | variable GAME_VERSION 2 | ||
string GAME_TITLE "Smell Restrictions" | |||
attribute OUTSIDE_LIFT | |||
variable FLOOR_MAPPING ground_floor first_floor second_floor | variable FLOOR_MAPPING ground_floor first_floor second_floor | ||
Line 12: | Line 13: | ||
{+intro | {+intro | ||
clear | clear | ||
write "^^ | write "^^Elevator and stairs example^^" | ||
execute "+look_around" | |||
} | } | ||
Line 23: | Line 24: | ||
short the "ground floor" | short the "ground floor" | ||
has OUTSIDE_LIFT | has OUTSIDE_LIFT | ||
up | up first_floor | ||
{look | {look | ||
write " | write "You are on the ground floor. The " | ||
if here(north) != nowhere | if here(north) != nowhere | ||
write "open " | write "open " | ||
Line 32: | Line 33: | ||
write "closed " | write "closed " | ||
endif | endif | ||
print: | |||
door door to an elevator is to the north and a set of stairs lead up. | |||
Beside the door is a call button.^ | |||
. | |||
} | } | ||
Line 46: | Line 49: | ||
{examine | {examine | ||
if here = ground_floor | if here = ground_floor | ||
write " | write "The stairs go up.^" | ||
endif | endif | ||
if here = first_floor | if here = first_floor | ||
write " | write "The go stairs up and down.^" | ||
endif | endif | ||
if here = second_floor | if here = second_floor | ||
write " | write "The go stairs down.^" | ||
endif | endif | ||
} | } | ||
Line 58: | Line 61: | ||
{take | {take | ||
if here = first_floor | if here = first_floor | ||
write " | write "Do you want to take the stairs up, or take the stairs down?^" | ||
endif | endif | ||
if here = ground_floor | if here = ground_floor | ||
Line 79: | Line 82: | ||
{+take_up | {+take_up | ||
write " | write "You can't take " noun1{the} " up.^" | ||
} | } | ||
Line 85: | Line 88: | ||
{+take_down | {+take_down | ||
write " | write "You can't take " noun1{the} " down.^" | ||
} | } | ||
object | object callbuttong: call button | ||
short a "call button" | short a "call button" | ||
floor 0 | floor 0 | ||
{examine | {examine : *examine_callbutton1 : *examine_callbutton2 | ||
write "Pushing this button summons the elevator to this floor. It's currently " | |||
if self has ON | |||
write "lit.^" | |||
else | |||
write "dark.^" | |||
endif | |||
} | } | ||
{press : | {press : *press_callbutton1 : *press_callbutton2 | ||
execute + | if lift_obj(moving_to) != arrived | ||
write "The button lights as you press it, only to go off again when you release it.^" | |||
return | |||
endif | |||
if lift_obj(floor) = self(floor) | |||
if here(out) = nowhere | |||
write "The lift doors slide open.^" | |||
execute "+lift_open" | |||
return | |||
endif | |||
write "The button lights as you press it, only to go off again when you " | |||
write "release it.^" | |||
return | |||
endall | |||
set lift_obj(moving_to) = self(floor) | |||
ensure self has ON | |||
write "The button lights up as you press it.^" | |||
} | } | ||
Line 104: | Line 128: | ||
{look | {look | ||
write " | write "You are inside the elevator. The door to the south is " | ||
if here(south) != nowhere | if here(south) != nowhere | ||
write "open, " | write "open, " | ||
Line 116: | Line 140: | ||
if COMPASS = south : COMPASS = out | if COMPASS = south : COMPASS = out | ||
if destination = nowhere | if destination = nowhere | ||
write " | write "The lift doors are currently closed.^" | ||
return | |||
endall | endall | ||
if destination = false | if destination = false | ||
write " | write "The only way out of the lift is to the west.^" | ||
return | |||
endif | endif | ||
return false | |||
} | } | ||
object | object cbutton: east eastern close door button control 1 | ||
short a "close doors button" | short a "close doors button" | ||
{press : move | {press : move | ||
if lift_obj(turns_till_doors_close) = 0 | if lift_obj(turns_till_doors_close) = 0 | ||
write " | write "The doors are already closed.^" | ||
set TIME = false | set TIME = false | ||
return | |||
endif | endif | ||
write " | write "The lift doors slide closed.^" | ||
execute "+lift_close" | execute "+lift_close" | ||
} | } | ||
object | object obutton: east eastern open door button control 1 | ||
short an "open doors button" | short an "open doors button" | ||
{press : move | {press : move | ||
if lift_obj(turns_till_doors_close) > 0 | if lift_obj(turns_till_doors_close) > 0 | ||
write " | write "The doors are already open.^" | ||
set TIME = false | set TIME = false | ||
return | |||
endif | endif | ||
if lift_obj(moving_to) != arrived | if lift_obj(moving_to) != arrived | ||
write " | write "The lift doors refuse to open while the lift is in motion.^" | ||
return | |||
endif | endif | ||
write " | write "The lift doors slide open.^" | ||
execute "+lift_open" | execute "+lift_open" | ||
} | } | ||
object gbutton: ground floor button g | |||
object | |||
short a "ground floor button" | short a "ground floor button" | ||
floor 0 | floor 0 | ||
{press : move | {press : move | ||
execute + | execute +floorbuttonpress<self | ||
} | } | ||
object | object 1button: first floor button 1 | ||
short a "first floor button" | short a "first floor button" | ||
floor 1 | floor 1 | ||
{press : move | {press : move | ||
execute + | execute +floorbuttonpress<self | ||
} | } | ||
object | object 2button: second floor button 2 | ||
short a "second floor button" | short a "second floor button" | ||
floor 2 | floor 2 | ||
{press : move | {press : move | ||
execute + | execute +floorbuttonpress<self | ||
} | } | ||
Line 205: | Line 208: | ||
{examine | {examine | ||
write " | write "The panel consists of five buttons labelled ground, one, two, " | ||
write "open and close. " | write "open and close. " | ||
if | if gbutton has ON | ||
write "The button for the ground floor is currently lit." | write "The button for the ground floor is currently lit." | ||
endif | endif | ||
if | if 1button has ON | ||
write "The button for the first floor is currently lit." | write "The button for the first floor is currently lit." | ||
endif | endif | ||
if | if 2button has ON | ||
write "The button for the second floor is currently lit." | write "The button for the second floor is currently lit." | ||
endif | endif | ||
Line 226: | Line 229: | ||
{examine | {examine | ||
write " | write "Above the panel is an LED display with a large red '" | ||
write led_display[lift_obj(floor)] "'.^" | write led_display[lift_obj(floor)] "'.^" | ||
} | } | ||
Line 233: | Line 236: | ||
constant floor 5 | constant floor 5 | ||
constant moving_to 6 | constant moving_to 6 | ||
constant arrived 42; POSSIBLE VALUE OF moving_to | |||
constant turns_till_doors_close | constant turns_till_doors_close 7 | ||
constant delta 8 | constant delta 8 | ||
Line 243: | Line 246: | ||
{examine | {examine | ||
if lift_obj(turns_till_doors_close) > 0; | if lift_obj(turns_till_doors_close) > 0; | ||
write " | write "The lift doors are open.^" | ||
else | else | ||
write " | write "The lift doors are closed.^" | ||
endif | endif | ||
} | } | ||
Line 251: | Line 254: | ||
{enter | {enter | ||
if here = lift | if here = lift | ||
write " | write "You are already in the lift.^" | ||
set TIME = false | set TIME = false | ||
return | |||
endif | endif | ||
proxy "east" | proxy "east" | ||
Line 260: | Line 263: | ||
{open | {open | ||
if lift_obj(turns_till_doors_close) > 0; | if lift_obj(turns_till_doors_close) > 0; | ||
write " | write "The lift doors are already open.^" | ||
return | |||
endif | endif | ||
if here = lift | if here = lift | ||
write " | write "(by pressing the open doors button)^" | ||
proxy "press open doors button" | proxy "press open doors button" | ||
return | |||
endif | endif | ||
write " | write "(by pressing the call button)^" | ||
proxy "press call button" | proxy "press call button" | ||
} | } | ||
Line 274: | Line 277: | ||
{close | {close | ||
if lift_obj(turns_till_doors_close) = 0; | if lift_obj(turns_till_doors_close) = 0; | ||
write " | write "The lift doors are already closed.^" | ||
break | break | ||
endif | endif | ||
if here = lift | if here = lift | ||
write " | write "(by pressing the close doors button)^" | ||
proxy "press close doors button" | proxy "press close doors button" | ||
return | |||
endif | endif | ||
write " | write "There is no way to close the lift doors from the outside.^" | ||
} | } | ||
Line 292: | Line 295: | ||
{look | {look | ||
write "< | write "<You are on the first floor. The " | ||
if here(north) != nowhere | if here(north) != nowhere | ||
write "open " | write "open " | ||
Line 298: | Line 301: | ||
write "closed " | write "closed " | ||
endif | endif | ||
print: | |||
door door to an elevator is to the north and a set of stairs lead up | |||
and down from here. Beside the door is a call button.^ | |||
. | |||
} | } | ||
{movement | {movement | ||
if +door_warning = true | |||
return true | |||
endif | |||
return false | |||
} | } | ||
object | object callbutton1: call button | ||
short a "call button" | short a "call button" | ||
floor 1 | floor 1 | ||
location second_floor : second floor | location second_floor : second floor | ||
Line 326: | Line 324: | ||
{look | {look | ||
write " | write "You are on the second floor. The " | ||
if here(north) != nowhere | if here(north) != nowhere | ||
write "open " | write "open " | ||
Line 332: | Line 330: | ||
write "closed " | write "closed " | ||
endif | endif | ||
print: | |||
door door to an elevator is to the north and a set of stairs lead | |||
down. Beside the door is a call button.^ | |||
. | |||
} | } | ||
Line 341: | Line 341: | ||
} | } | ||
object | object callbutton2: call button | ||
short a "call button" | short a "call button" | ||
floor 2 | floor 2 | ||
{+lift_close | {+lift_close | ||
Line 386: | Line 378: | ||
if lift_obj(turns_till_doors_close) = 0 | if lift_obj(turns_till_doors_close) = 0 | ||
if here = lift : here = FLOOR_MAPPING[lift_obj(floor)] | if here = lift : here = FLOOR_MAPPING[lift_obj(floor)] | ||
write " | write "^The lift doors slide closed.^" | ||
endif | endif | ||
execute "+lift_close" | execute "+lift_close" | ||
endif | endif | ||
return # THE LIFT CAN'T DO ANYTHING ELSE UNTIL THE DOORS HAVE CLOSED | |||
endif | endif | ||
if lift_obj(moving_to) != arrived | if lift_obj(moving_to) != arrived | ||
Line 403: | Line 395: | ||
endif | endif | ||
if here = lift | if here = lift | ||
write " | write "^The lift vibrates as it slowly " | ||
if lift_obj(delta) < 0 | if lift_obj(delta) < 0 | ||
write "descends.^" | write "descends.^" | ||
Line 410: | Line 402: | ||
endif | endif | ||
endif | endif | ||
return | |||
endif | endif | ||
set lift_obj(moving_to) = arrived | set lift_obj(moving_to) = arrived | ||
if here = FLOOR_MAPPING[lift_obj(floor)] | if here = FLOOR_MAPPING[lift_obj(floor)] | ||
write " | write "^A crisp-sounding bell rings briefly and the doors " | ||
write "to the lift slide open.^" | write "to the lift slide open.^" | ||
endif | endif | ||
if here = lift | if here = lift | ||
write " | write "^Having arrived at the selected floor, the lift " | ||
write "gently comes to a halt and the doors open.^" | write "gently comes to a halt and the doors open.^" | ||
endif | endif | ||
execute "+lift_open" | execute "+lift_open" | ||
execute "+ | execute "+disable_callbuttons" | ||
endif | endif | ||
} | } | ||
{+ | {+press_callbutton | ||
if arg[0] has ON | if arg[0] has ON | ||
write " | write "The call button has already been pressed.^" | ||
set TIME = false | set TIME = false | ||
return | |||
endif | endif | ||
if lift_obj(floor) = arg[0](floor) | if lift_obj(floor) = arg[0](floor) | ||
if lift_obj(turns_till_doors_close) > 0 | if lift_obj(turns_till_doors_close) > 0 | ||
write " | write "There is already a lift here.^" | ||
set TIME = false | set TIME = false | ||
return | |||
endif | endif | ||
write " | write "A crisp-sounding bell rings briefly and the doors " | ||
write "to the lift slide open.^" | write "to the lift slide open.^" | ||
execute "+lift_open" | execute "+lift_open" | ||
ensure arg[0] hasnt ON | ensure arg[0] hasnt ON | ||
return | |||
endif | endif | ||
write "<p>As you press the call button it lights up.^" | write "<p>As you press the call button it lights up.^" | ||
Line 449: | Line 441: | ||
} | } | ||
{+ | {+disable_callbuttons | ||
ensure gbutton hasnt ON | |||
ensure 1button hasnt ON | |||
ensure 2button hasnt ON | |||
ensure callbuttong hasnt ON | |||
ensure callbutton1 hasnt ON | |||
ensure callbutton2 hasnt ON | |||
ensure | |||
ensure | |||
ensure | |||
ensure | |||
ensure | |||
ensure | |||
} | } | ||
Line 471: | Line 453: | ||
if COMPASS = north : COMPASS = in | if COMPASS = north : COMPASS = in | ||
if destination = false | if destination = false | ||
write " | write "The lift doors are closed.^" | ||
return | |||
endif | endif | ||
endif | endif | ||
return false | |||
} | } | ||
Line 485: | Line 467: | ||
player | player | ||
#include "verbs.library" | |||
</pre> | </pre> | ||
[[Category:Elevator and stairs (Example)]] | [[Category:Elevator and stairs (Example)]] |
Latest revision as of 02:07, 11 February 2010
The guy who did the Inform example wasn't wrong...
#!../bin/jacl variable GAME_VERSION 2 string GAME_TITLE "Smell Restrictions" attribute OUTSIDE_LIFT variable FLOOR_MAPPING ground_floor first_floor second_floor {+intro clear write "^^Elevator and stairs example^^" execute "+look_around" } {+eachturn execute "+lift_action" } location ground_floor : ground floor short the "ground floor" has OUTSIDE_LIFT up first_floor {look write "You are on the ground floor. The " if here(north) != nowhere write "open " else write "closed " endif print: door door to an elevator is to the north and a set of stairs lead up. Beside the door is a call button.^ . } {movement break +door_warning break false } object stairs : stairs mass scenery {examine if here = ground_floor write "The stairs go up.^" endif if here = first_floor write "The go stairs up and down.^" endif if here = second_floor write "The go stairs down.^" endif } {take if here = first_floor write "Do you want to take the stairs up, or take the stairs down?^" endif if here = ground_floor proxy "up" endif if here = second_floor proxy "down" endif } {take_up proxy "up" } {take_down proxy "down" } grammar take *here up >take_up {+take_up write "You can't take " noun1{the} " up.^" } grammar take *here down >take_down {+take_down write "You can't take " noun1{the} " down.^" } object callbuttong: call button short a "call button" floor 0 {examine : *examine_callbutton1 : *examine_callbutton2 write "Pushing this button summons the elevator to this floor. It's currently " if self has ON write "lit.^" else write "dark.^" endif } {press : *press_callbutton1 : *press_callbutton2 if lift_obj(moving_to) != arrived write "The button lights as you press it, only to go off again when you release it.^" return endif if lift_obj(floor) = self(floor) if here(out) = nowhere write "The lift doors slide open.^" execute "+lift_open" return endif write "The button lights as you press it, only to go off again when you " write "release it.^" return endall set lift_obj(moving_to) = self(floor) ensure self has ON write "The button lights up as you press it.^" } location lift : lift short the "elevator" {look write "You are inside the elevator. The door to the south is " if here(south) != nowhere write "open, " else write "closed, " endif write "and there is the usual panel of buttons beside it.^" } {movement if COMPASS = south : COMPASS = out if destination = nowhere write "The lift doors are currently closed.^" return endall if destination = false write "The only way out of the lift is to the west.^" return endif return false } object cbutton: east eastern close door button control 1 short a "close doors button" {press : move if lift_obj(turns_till_doors_close) = 0 write "The doors are already closed.^" set TIME = false return endif write "The lift doors slide closed.^" execute "+lift_close" } object obutton: east eastern open door button control 1 short an "open doors button" {press : move if lift_obj(turns_till_doors_close) > 0 write "The doors are already open.^" set TIME = false return endif if lift_obj(moving_to) != arrived write "The lift doors refuse to open while the lift is in motion.^" return endif write "The lift doors slide open.^" execute "+lift_open" } object gbutton: ground floor button g short a "ground floor button" floor 0 {press : move execute +floorbuttonpress<self } object 1button: first floor button 1 short a "first floor button" floor 1 {press : move execute +floorbuttonpress<self } object 2button: second floor button 2 short a "second floor button" floor 2 {press : move execute +floorbuttonpress<self } object panel : panel of buttons short a "panel of buttons" {examine write "The panel consists of five buttons labelled ground, one, two, " write "open and close. " if gbutton has ON write "The button for the ground floor is currently lit." endif if 1button has ON write "The button for the first floor is currently lit." endif if 2button has ON write "The button for the second floor is currently lit." endif write ^ execute examine_display } string led_display G 1 2 object display : led display short an "LED display" {examine write "Above the panel is an LED display with a large red '" write led_display[lift_obj(floor)] "'.^" } # Elements of lift object: constant floor 5 constant moving_to 6 constant arrived 42; POSSIBLE VALUE OF moving_to constant turns_till_doors_close 7 constant delta 8 object lift_obj: lift door doors short name "east lift" moving_to arrived {examine if lift_obj(turns_till_doors_close) > 0; write "The lift doors are open.^" else write "The lift doors are closed.^" endif } {enter if here = lift write "You are already in the lift.^" set TIME = false return endif proxy "east" } {open if lift_obj(turns_till_doors_close) > 0; write "The lift doors are already open.^" return endif if here = lift write "(by pressing the open doors button)^" proxy "press open doors button" return endif write "(by pressing the call button)^" proxy "press call button" } {close if lift_obj(turns_till_doors_close) = 0; write "The lift doors are already closed.^" break endif if here = lift write "(by pressing the close doors button)^" proxy "press close doors button" return endif write "There is no way to close the lift doors from the outside.^" } location first_floor : first floor short the "first floor" has OUTSIDE_LIFT down ground_floor up second_floor {look write "<You are on the first floor. The " if here(north) != nowhere write "open " else write "closed " endif print: door door to an elevator is to the north and a set of stairs lead up and down from here. Beside the door is a call button.^ . } {movement if +door_warning = true return true endif return false } object callbutton1: call button short a "call button" floor 1 location second_floor : second floor short the "second floor" has OUTSIDE_LIFT down first_floor {look write "You are on the second floor. The " if here(north) != nowhere write "open " else write "closed " endif print: door door to an elevator is to the north and a set of stairs lead down. Beside the door is a call button.^ . } {movement break +door_warning break false } object callbutton2: call button short a "call button" floor 2 {+lift_close set lift_obj(turns_till_doors_close) = 0 set noun3 = FLOOR_MAPPING[lift_obj(floor)] set lift(south) = nowhere set lift(out) = nowhere set lift(south) = nowhere set lift(out) = nowhere set noun3(in) = nowhere set noun3(north) = nowhere } {+lift_open set lift_obj(turns_till_doors_close) = 3; set noun3 = FLOOR_MAPPING[lift_obj(floor)] set lift(south) = noun3 set lift(out) = noun3 set noun3(in) = lift set noun3(north) = lift } {+lift_action if here = lift move lift_obj to here endif if here has OUTSIDE_LIFT move stairs to here move lift_obj to here endif if lift_obj(turns_till_doors_close) > 0 # THE LIFT DOORS ARE OPEN... set lift_obj(turns_till_doors_close) - 1 if lift_obj(turns_till_doors_close) = 0 if here = lift : here = FLOOR_MAPPING[lift_obj(floor)] write "^The lift doors slide closed.^" endif execute "+lift_close" endif return # THE LIFT CAN'T DO ANYTHING ELSE UNTIL THE DOORS HAVE CLOSED endif if lift_obj(moving_to) != arrived if lift_obj(moving_to) != lift_obj(floor) # THE LIFT IS STILL ON ITS WAY TO SOMEWHERE set lift_obj(delta) = lift_obj(moving_to) set lift_obj(delta) - lift_obj(floor) if lift_obj(delta) < 0 set lift_obj(floor) - 1 else set lift_obj(floor) + 1 endif if here = lift write "^The lift vibrates as it slowly " if lift_obj(delta) < 0 write "descends.^" else write "ascends.^" endif endif return endif set lift_obj(moving_to) = arrived if here = FLOOR_MAPPING[lift_obj(floor)] write "^A crisp-sounding bell rings briefly and the doors " write "to the lift slide open.^" endif if here = lift write "^Having arrived at the selected floor, the lift " write "gently comes to a halt and the doors open.^" endif execute "+lift_open" execute "+disable_callbuttons" endif } {+press_callbutton if arg[0] has ON write "The call button has already been pressed.^" set TIME = false return endif if lift_obj(floor) = arg[0](floor) if lift_obj(turns_till_doors_close) > 0 write "There is already a lift here.^" set TIME = false return endif write "A crisp-sounding bell rings briefly and the doors " write "to the lift slide open.^" execute "+lift_open" ensure arg[0] hasnt ON return endif write "<p>As you press the call button it lights up.^" ensure arg[0] has ON set lift_obj(moving_to) = arg[0](floor) } {+disable_callbuttons ensure gbutton hasnt ON ensure 1button hasnt ON ensure 2button hasnt ON ensure callbuttong hasnt ON ensure callbutton1 hasnt ON ensure callbutton2 hasnt ON } {+door_warning if COMPASS = north : COMPASS = in if destination = false write "The lift doors are closed.^" return endif endif return false } object kryten: myself self me has ANIMATE short name "yourself" quantity 50 parent ground_floor player #include "verbs.library"