DEV website instance!The main loop – house-keepingAfter initialisation comes the main program loop. This can be thought of as consisting of three parts. First comes the general per-turn house-keeping (e.g. determining whether the current location is lit, whether the player is getting thirsty, whether there is some NPC action to be announced...). Secondly, the player's input is obtained and parsed. Thirdly player command is responded to. For clarity, I prefer to separate them into individual REPEAT sections, which get executed in the order of their declaration. In this game, there isn't much house-keeping required: repeat ifflag status, moved # Has the player moved? call describe.here # If so describe their new location fin Brief as it is, this section packs a lot of new stuff. Firstly, STATUS is a global variable. It must be present in any A-code game, so if not declared explicitly in the game's source, it is declared automatically by the acdc translator. We shall meet its other uses further on, but for the moment it is enough to know that like all variables (global or local), in addition to carrying a value, it has a set of binary flags associated with it. In this particular case, the relevant flag is called MOVED. This flag is optional – if declared by the game, it is set by the kernel to true if the last simple command resulted in a change of location and to false otherwise. We haven's actually declared that flag yet, but that's all right – A-code allows you to use entities before their declaration. So let's declare it now: flags variable MOVED # Optional STATUS variable flag, maintained by the kernel This declares a flag which can be used with variables (but not places or objects). Back to house-keeping... As you may guess, the IFFLAG directive in the above code snippet checks whether the MOVED flag of the STATUS variable is set to true and if so, causes execution of the following code, up to the corresponding FIN directive closing the conditional code block. (Block's indentation is irrelevant and only used to enhance code readability.) In this case, the conditional code does nothing more than call a procedure, (that is a named chunk of code) called DESCRIBE.HERE. As the name suggests, it will describe the current location. Let's attend to it straight away.
|