! STDLIB.AGT: A collection of useful subroutines. ! ! This file is in the public domain. ! ! To use this file, place "#include stdlib.agt" near the beginning ! of your game. ! ! This file defines two variables for internal use: ! [loop routine] (used to pass your subroutines to the the subroutines ! in this library) ! [arg] (used to hold arguments to subroutines, both yours and ! the ones in this library) ! ! At the moment, there is only two subroutine here: ! ! Subroutine [object loop]: Does something to every noun, and creature in ! the game. To use, write a subroutine that does whatever you want ! to the object contained in [arg]. Then set the variable ! [loop routine] to equal this subroutine and invoke [object loop]. ! See MANSION.AGT for an example. ! ! Subroutine [get direction]: If $verb$ is a direction verb ! (NORTH, SOUTH, etc.), this sets [arg] equal to the direction ! number (1 through 12). Otherwise, this sets [arg] to 0. subroutines [object loop] [get direction] end_subroutines variable [loop routine] variable [arg] ! Subroutine to loop over all nouns and creatures in the game ! Set [loop routine] to the subroutine to call for each object. ! The variable [arg] will contain the current object. COMMAND SUBROUTINE[object loop] Set [arg] [magx:first noun] 1 2 GT [arg] [magx:last noun] ! If we reach end of nouns, start creats LT [arg] [magx:first creature] Set [arg] [magx:first creature] 2 GT [arg] [magx:last creature] ! If last creature, we're done Return 2 DoSubroutine [loop routine] Add [arg] 1 Prev 1 END_COMMAND ! Subroutine to convert a direction command to a number COMMAND SUBROUTINE[get direction] Set [arg] 1 1 NOT DirectionIs [arg] LT [arg] 12 Add [arg] 1 ! Try the next direction Prev 1 1 DirectionIs [arg] ! We have a match Return 1 Set [arg] 0 ! No match Return END_COMMAND