Site Tools
User Tools

Objects and Inventories: 1

Needs

- One memory slot for each object.
- A universal program.

Outline

You'd like to have objects in your Place. Things that your guest can pick up and carry around. Maybe as part of a puzzle, your guest has to work out to pick up the key/fire extinguisher/bagpipes here and use their items there. Maybe they have to collect certain items, be they parts of a machine that they have to assemble, treasure objects in a treasure hunt or anything else that you can think of. Maybe you're building some sort of adventure arena,1) and you'd like to have movable objects in it. This page shows you how to build a simple system to do this.

This article will give a simplified version of an object/inventory program. The major drawback of this system is that you can't leave objects in arbitrary places as you might want to in a real “adventure” game, and your guest cannot drop anything just where they want. It also has no limit on what they can carry. If you want your guests to be able to put down and pick back up items in arbitrary rooms and/or to have limits on how much they can carry, then I hope to address this in a future article.2)

Mechanics

The core of all this is quite simple. You have to use memories3) and you use one memory slot for each object that you want to have, together with a code to say what each value for the slot represents, as explained here. At it's simplest this could just be 0 for “object in it's starting position” and 1 for “object found and picked up by guest”, more complicated schemes might keep track of other related information.

So for example, you might have a teapot as an object, with the third slot in the memory Objects dedicated to it. Then you could have the code:

Objects Slot 3 Where's the teapot?
0 On the table in the kitchen
1 Being carried by the guest
2 Has been given to NPC Fred Bloggs as a bribe.
No longer exists.

In the particular locations where something can happen you then test the memory slot to see if it holds the appropriate value and then act accordingly. So with the above example, in the kitchen you might have a program which tests to see if your guest has entered a command containing the words “take” and “teapot” then tests to see if the teapot is still on the table and if so, then adds 100 to the memory Objects and displays a page saying something like “You pick up the teapot and stuff it in your backpack.”

Adding An Inventory Command

So far so good, this is just a reasonably straight forward application of memories and memory slots. We want more than this. We want the player to be able to see what they're carrying. You want to build in an 'Inventory' command. To achieve this, we need a little preliminary work. First of all, for each movable object that you have in your place you need a page decorated with a description of this object. This is what will be shown when your guest looks at their inventory. I personally favour having short descriptions for this purpose, so in the above teapot example I'd just decorate the page as “A teapot.” or possibly “A china teapot.” You may disagree and prefer a more verbose or even florid description “A yellow china teapot decorated with delicate pictures of nymphs and satyrs frolicking in Arcadia.” or even more. This is a design decision that is of course entirely up to you.

Once this is done we can start programming. For each of your objects have a program called “Hold object4) which simply checks to see if your guest is holding that item, and if so then shows its description page. So continuing the above example, in the first line of your Hold Teapot program have a Memory Part Equal Contrivance set to check that the third place in the Objects memory is one. Beneath this have a Show Page Contraption pointing to the Teapot description page.

Once this is done for all your objects, have one master program called “Carried Objects”5) which consists exclusively of Run Program contraptions pointing to each of your individual Hold object programs. Finally build your Inventory program. Start off with a check to see if your guest wants to see their inventory. I use three Exact Match Commentary contrivances, set to watch out for /Inventory, /Inv or /I respectively and set the Flow Control Knob so that the line passes if any of the individual contrivances pass, you may decide to have something different. On the next line simply put a Run program pointing to Carried Objects program. Now one last Run Program pointing to your new Inventory program placed in your universal program, and the job's done.

You may have noticed that the Inventory program and the Carried Objects program could easily be amalgamated into one program. First line have the “are they looking at their inventory?” test, and then put the Run Programs for all the objects on subsequent lines. This is true,it will work and even be simpler and quicker to build. However, in subsequent articles I will be adding bells and whistles to this basic set up. More will be added to each of the Hold Object programs as they will be called for different purposes. Each of these uses will have its own 'shell' program, each of which will call the Carried Objects program to different ends. Hence it will be much more convenient to set things up this way.


Return to Places Overview

1)
Like Valskyr, at the StoneHenge at (22,35) for example.
2)
Please bare in mind that I'm writing this at a rate of about one article every six months, and there's no guarantee that the next one will be about objects. Hey! I do have other things to do with my life you know?
3)
This should be obvious; you need memories to remember anything at all
4)
The name isn't strictly necessary of course, however it is a good descriptive name, and furthermore it's the name by which I will be refering to these programs, so it may help avoid confusion if you use it.
5)
Again, the exact name isn't strictly necessary, but it's a good one and the one I'll use.
gameplay/guides/places/objectsandinventories.txt · Last modified: 2023/11/22 05:19 by kuhsodas