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 > Checking Our Inventory

Checking Our Inventory

Finally, let’s create a function that lets players see an inventory of objects they are carrying:

(defun inventory ()
  (cons 'items- (objects-at 'body *objects* *object-locations*)))

This inventory function uses the objects-at function to retrieve a list of objects at a requested location. What location does it search for? If you remember, when an object was picked up by the player, we changed its location to 'body: This is the location we now use to query.

Let’s try out this inventory function:

> (inventory)
(ITEMS- WHISKEY)

As you can see, we are carrying only one item right now: the whiskey bottle we just picked up.

There you have it! We now have a basic engine for a text adventure game. We can look around the world with look; walk between places with walk; pick up objects with pickup; and check our inventory with inventory.


  

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