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 ...

Get Land of Lisp now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.