Dealing with Qualities

You must understand the Game Editor concepts, before post here.

Dealing with Qualities

Postby Fuzzy » Wed Jun 28, 2006 8:46 am

Remember each time you use IF a bunny dies. So avoid IF folks.

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.

Image

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!]
Last edited by Fuzzy on Wed Jun 28, 2006 9:56 pm, edited 3 times in total.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby jazz_e_bob » Wed Jun 28, 2006 9:18 am

This is a great post. Thankyou.
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score

Postby makslane » Wed Jun 28, 2006 12:11 pm

Great post, thanks!
Only few corrections:

If you want test individual traits, like burn, you must use bit operations, not arithmetic operations.

So, dont use + to combine the traits.
Use the bit operator | (or)

And, to test if a trait was set, use the bit operator & (and)
Note, && is for boolean operations.
& is for bit operations.

So, the code to combine will be:

Code: Select all
Rock.Traits = hard | heavy | dry;


And code to test burn:

Code: Select all
if (traits & burns)
{
     destroy actor;
}
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Fuzzy » Wed Jun 28, 2006 1:35 pm

Oops! You are right! Thanks for the corrections Makslane. I will go back and fix things.

I always get the bit and boolean operators mixed up.

I do think, if you use only powers of two you can get away with + and -? but of course the bitwise operators are faster, and more syntaxically correct.
Code: Select all
  2  +  8   =  10      or
0010 + 1000 = 1010


is the same end result as
Code: Select all
2 | 8


But for anyone reading, do as Makslane says, use the | operator.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby makslane » Wed Jun 28, 2006 2:07 pm

+ is not |
Don't works for 2 and 10 for example
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby jazz_e_bob » Wed Jun 28, 2006 8:33 pm

How did you break the fork off the stick?

Stick.Traits -= forked; ?
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score

Postby Fuzzy » Wed Jun 28, 2006 9:41 pm

jazz_e_bob wrote:How did you break the fork off the stick?

Stick.Traits -= forked; ?


Nope. Try this Jazz_e_bob...

Stick.traits ^= forked;

Thats called xor, and works similar to |, but what it does is toggle back and forth. Try it out with a textNumber to see how that works. The trick that is that if there was no fork in the first place, it will add one.

I just want to point out an important BAD thing I did in that qualities list. You cannot use the word 'long' as it is an important keyword for C (and GE).
Last edited by Fuzzy on Wed Jun 28, 2006 9:53 pm, edited 1 time in total.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Dealing with Qualities

Postby DilloDude » Wed Jun 28, 2006 9:42 pm

ThreeFingerPete wrote:Remember each time you use IF a bunny dies.

Kill the bunnies! :twisted: IF! IF! IF! IF! IF!... :twisted:
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby zoiba » Wed Feb 14, 2007 9:51 am

this is a great tip! thanx Fuzzy
User avatar
zoiba
 
Posts: 45
Joined: Mon Aug 09, 2004 9:44 am
Location: Italy
Score: 1 Give a positive score

Postby Sgt. Sparky » Sat Feb 17, 2007 4:18 pm

:shock: Wow, it's awsome! :D

look at the locations right above mine, A chair (in) italy :lol:
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby irblinx » Thu Feb 22, 2007 12:47 pm

Nicely explained
irblinx
http://www.irblinx.me.uk/Crania.htm
Current projects: Crania deluxe for Mac, iCrania
User avatar
irblinx
 
Posts: 122
Joined: Wed Apr 19, 2006 11:15 am
Location: Manchester, UK
Score: 6 Give a positive score

Re: Dealing with Qualities

Postby Sgt. Sparky » Thu Feb 22, 2007 3:11 pm

DilloDude wrote:
ThreeFingerPete wrote:Remember each time you use IF a bunny dies.

Kill the bunnies! :twisted: IF! IF! IF! IF! IF!... :twisted:

I woike a widdle wabbit! :cry:
use IF I do not shoot a person who said "IF! IF! IF! IF! IF!..."
:cry:
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Game A Gogo » Fri Feb 23, 2007 1:48 am

a bunny is born every time an IF statement is used correctly.

Problem solved!
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby Troodon » Sat Feb 24, 2007 11:44 am

if (bunny.population >= 1)
{
a bunny dies;
}
else if (bunny.population == 0)
{
create *10* bunnies;
}

This solves all the problems! :D





Btw what's bunny? I can't find it from dictionarry and english isn't my first language.
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby Fuzzy » Sat Feb 24, 2007 1:07 pm

A bunny is a baby rabbit.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Next

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest