Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

5. Building a Text Game Engine > Picking Up Objects

Picking Up Objects

Next, let’s create a command to pick up objects in our world. To do so, we modify the variable *object-locations* that we’re using to track the location of objects:

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

The pickup function uses the member function to see if the object is indeed on the floor of the current location. (The member function checks to see if a particular item is found in a list of items.) We use the objects-at command to generate the lists of objects at the current location.

If the object is at the current location, we use the push command to push a new item onto the *object-locations* list, consisting of the item and its new location. The new location will just be body, for the player’s body.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint