DEV website instance!Named procedure declarationHere's that procedure for describing locations: proc DESCRIBE.HERE local optr # Local pointer to objects say here # Show description of current location itobj optr, here # Loop through objects at this location say optr # Show such objects fin # Loop terminator Once again, this brief declaration introduces several important concepts. The LOCAL OPTR statement declares a variable called OPTR, which is local to this code section (i.e. to this procedure). All other variables (whether declared explicitly by the VARIABLE major directive or are are supplied automatically by the A-code kernel) are global in scope. Declaration of local variables forms the sole exception to general rules in that any LOCAL declaration lines must be placed at the very beginning of the code section to which they apply. I've called this variable OPTR because it will be used as a pointer to objects. Pointers are just variables which happen to be referencing some game entity (object, place, text, word or variable). In almost all cases, if a variable containing a pointer value is used in some context where a game entity is expected, the effect is as if the entity pointed to were used. So in our case, the SAY directive will display the description of the player's current location, as if that location was explicitly named as its argument. The SAY HERE statement displays the description of the current location. This is because HERE is an automatic variable, which is maintained by the kernel and always point to the player's current location. (There is also the companion automatic variable THERE, which always points to the player's location prior to the last location change. We do not need it in this game.) The ITOBJ directive iterates through game's objects, executing for each one the following code, up to the matching FIN statement. It can be qualified by a location (as in this case) and/or by an object flag or flags, in which case any non-matching objects are ignored. Thus ITOBJ OPTR, HERE will only consider objects in the current location. As you may have gathered from the above, SAY OPTR will give the description of the object pointed to. It will not be the inventory description, which would be automatically used if the object in question were carried by the player. And it will not be the detailed description, because that is only shown by the DESCRIBE directive.
|