Now we'll create a command to pickup objects in our world:

      (defun pickup-object (object)
        (cond ((is-at object location object-locations)
               (push (list object 'body) object-locations)
               `(you are now carrying the ,object))
    	   (t '(you cannot get that.))))

This function checks to see if the object is indeed on the floor of the current location- If it is, it pushes the new location (the player's body) onto the list (pushing means to add a new item to the list, in a way that the `assoc` command sees and therefore hides the previous location) and returns a sentence letting us know whether it succeeded.
Now let's cast another SPEL to make the command easier to use:

      (defspel pickup (object)
        `(pickup-object ',object))

Now let's try our newest SPEL:

      (pickup whiskey-bottle)

      ==> (you are now carrying the whiskey-bottle)

Now let's add a couple more useful commands. First, a command that lets us see our current inventory of items we're carrying:

      (defun inventory ()
        (remove-if-not (lambda (x)
    		     (is-at x 'body object-locations))
    		   objects))

Now a function that tells us if we have a certain object with us:

      (defun have (object)
        (member object (inventory)))

<< begin < previous - next > end >>