Ok. This is a somewhat advanced topic. I've dealt with this in other aspects, but I am going to expand on it.
First, you have a stick.

So lovely. So brown.
Here is the setup. You are making a adventure game, and the player character is lost on an island, and must find and build the tools needed to survive. The stick is an object that can be used to create several other types of useful objects.
Part of the puzzle is for the player to build items, rather than just find them. You plan it to be open ended, so the player may even create things you didnt plan for.
So. A stick. We will deal with sticks, and you can extrapoliate this to other raw materials.
We make a list of qualities of objects in our world, and use define for them. The two important parts are that they are independant of each other, and that we define them in a way that they dont overlap. We use define statements, and powers of two(including 1). You cannot use 3. You cannot use 6. You will not use 10. Each is double the last.
Here are some possible raw object traits in our world.
- Code: Select all
#define lengthy 2
#define hard 4
#define burns 8
#define straight 16
#define heavy 32
#define forked 64
#define shiny 128
#define dry 256
you get the idea...
now, in the stick actor, we have a integer variable(all game objects would have this too). Lets call it Traits. in the sticks create actor event, we put
- Code: Select all
Stick.Traits = long | burns | straight | forked | dry;
you might want to put hard in there too. I decided that hard would be better for really hard things, like rocks.
- Code: Select all
Rock.Traits = hard | heavy | dry;
Easy hey? Here is where it gets fun.
The player gathers a rock and a stick. He breaks the fork off the stick, so now its....
- Code: Select all
Stick.Traits = long | burns | straight | dry;
and you can use a comparison on two sticks to see if they are the same, or if a stick can be used for an item.
- Code: Select all
if (stick.traits == otherobject.traits)
{
do stuff
}
or...
if the player makes his axe, and drops it in the fire, you check to decide if it will burn(because he might make an all metal axe!)
- Code: Select all
if (traits & burns)
{
destroyactor();
}
This leaves everything open ended(other than the graphic), and saves you a bunch of IF statements checking each possible item type to see what effect it has. Just check the Traits variable!
Oh, and you can have only a certain amount of traits. The largest numbered define would be one half of max integer(which is a lot!).
[edited to correct errors, errors, more errors. Thanks Makslane!]