DEV website instance!More actionsBy now you should have no problem following the below code for hanging the cloak. The only directive that needs explaining is IFNEAR CLOAK, which tests for the cloak being present, whether or not it is carried by the player. IFNEAR is a shorthand for IFHAVE followed by OR followed by IFHERE. action hang cloak ifnear cloak ifat cloakroom # True only if the player is at the cloakroom ifeq cloak, 2 # Already hanging -- nothing to do quip "It is already hanging on the hook!" fin ifhave, cloak # True only if the cloak is in the players' possession drop cloak # Make sure it is not carried fin set hook, 1 # Include the cloak in the hook's description set cloak, 2 # Set the cloak to have no description set bar, 1 # Bar is now lit quip "You hang the cloak on the hook." fin fin That leaves just two more actions to be defined – READ and LOOK: action read ifeq status, 1 # Player said READ - we'll default to READ MESSAGE or ifkey message # Player actually said READ MESSAGE and ifat bar #Player is at the bar and ifeq bar, 1 # If the bar is lit say message # "Lost" or "won", depends on the message's value stop fin Recall the as-you-go parsing of compound IFs. The above one says that if the player said READ or READ MESSAGE, and is at the bar, and the bar is lit then the message is displayed and the game terminated. Recall also that the value of message was originally set to 4 and decremented any time the player did something in darkness other than leaving the bar. The message description is a text switch and will give the "you win" win description for values 1 through 4, and the "you lose" one for message values of zero or less. Finally, LOOK. If no object is given, it just needs to call the DESCRIBE.HERE procedure, which we have already constructed for use by the REPEAT loop. If an object is nominated and is nearby (carried or just present) and the object in question is the message, that's already covered by the READ action – so just CALL READ. Otherwise DESCRIBE ARG2 does the job. action look ifeq status, 1 call describe.here # The procedure does not QUIT... quit # ... so QUIT explicitly fin ifnear arg2 ifkey message # If the object to be describe is the message... call read # ... just call the code for READ. fin describe arg2 # Otherwise give long object description quit fin An that's it. Well, sort of...
|