DEV website instance!Location-specific codeNow for the game code specific to game's locations. This is declared using the major directive AT. Yes, it could have been defined as a part of location definitions, but that's not how Dave Platt structured it. If preferred, individual AT code definitions can be placed immediately after the corresponding PLACE definition. Conventionally, though, all PLACE definitions are grouped together and so do all AT code definitions. In the foyer, the player can go south or west, attempt to move north or east, look around and attempt to drop the cloak. However, trying to move in a direction in which there are no exits is handled generically by the error handling REPEAT section, so only legal exits need to be catered for. Similarly, looking around and dropping things are generally not location specific, so are better left to verb-associated code to handle later. That's not to say that we can't intercept such actions at location-specific code, if more convenient. at foyer move south, bar move west, cloakroom respond north "You've only just arrived, and besides, the weather outside seems to be getting worse." The MOVE opcode is a conditional version of GOTO. It takes a variable number of arguments, of which the last one is the location to move the player to, if the last player command contained one of the words listed before the location name. The cloakroom code is self-explanatory. Again, other actions will be handled by code specific to individual verbs. The bar is a little bit more complicated. at cloakroom move east, foyer at bar move north, foyer ifloc cloak, cloakroom else # The cloak is not in the cloakroom sub message, 1 # Count attempted actions in the dark quip "Blundering around in the dark isn't a good idea!" fin As one might expect, the IFLOC directive checks whether its first argument (which must be an object or a variable pointing at an object) is in one of locations listed by the rest of the directives arguments. In this case we want to do something when the cloak is not in the cloakroom. This is done by using the ELSE directive which executes code if the IF test returns false. As usual, a test can have separate code to be executed when the condition is satisfied and when it is not. What happens at the bar is that if the cloak is not at the cloakroom, the value of the object MESSAGE, which was set to 4 in the game's initialisation (the INIT section) is decremented (you will see why later). Because there is no action that can be performed in the dark bar, it makes sense to ignore the player's command and abort the REPEAT loop with a warning message about blundering in the dark.
|