Free up processing, use 1 variable :)

Talk about making games.

Free up processing, use 1 variable :)

Postby Hblade » Thu Jul 22, 2010 9:02 am

This idea was actually obtained while using RPG Maker VX / XP

You can run the entire game off of 1 variable. Go to global code, click "Variables". click add. Make a variable called GAME_VARIABLES, or what ever you like :3

Where it says Array, click Yes, then make it the max size, 32000, for now. You can change the array size once your done making your game.

Now in Global Code, Define your variables like so:
Code: Select all
#define SHOOT 0
#define ENEMY_SHOOT 1
#define DIFICULTY 2
#define SPAWN_TIME 3
#define HP 4
#define ENEMY_HP 5
#define SCORE 6

Those are pretty much your non-process eating variables :D! Oh, but one more thing. Go back to variables and click GAME_VARIABLES, then click edit. Make it a "real" that way you can also store decimals :)

To edit one of your defined variables, or read from them, simply do this:
Code: Select all
GAME_VARIABLES[HP] = 34;

This will make the HP = 34 :D

To read from a variable using a text actor, for example score
Code: Select all
sprintf(text, "%g", GAME_VARIABLES[SCORE]);


Hope this helped :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Free up processing, use 1 variable :)

Postby lcl » Thu Jul 22, 2010 12:32 pm

Hey that's good idea! :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Free up processing, use 1 variable :)

Postby Hblade » Thu Jul 22, 2010 2:39 pm

thanks
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Free up processing, use 1 variable :)

Postby jimmynewguy » Thu Jul 22, 2010 4:22 pm

But doesn't that make all those variables global? All the enemies would be sharing health, I think....I don't really use arrays but by just looking at this it seems this is so. But besides that all your global variables can be one thing, which helps alot! Thanks :)
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Free up processing, use 1 variable :)

Postby Hblade » Thu Jul 22, 2010 4:33 pm

exactly, thats why I guess just make a few more variables for health. This atleast helps a bit with the globals :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Free up processing, use 1 variable :)

Postby Bee-Ant » Thu Jul 22, 2010 5:46 pm

Free up your processing or free up your computer processing???
If you mean your computer, then I think it's wrong.
Using a single variable doesn't mean speed up your performance...
Let me explain...

- You use Double/Real type variable there, it's size is 8 bytes...
- You use 32000 spaces, so it's 8*32000=256000 bytes
- You use 7 #defines...well I dunno the size, but so far you've already allocated your memory over 256000 bytes

Remember, array ALWAYS allocate memory, whether you fill it or not.
So in this case, it's better to use 7 different real variables non array. They will allocate 56 bytes only...

For more variable size, lookie here http://www.cplusplus.com/doc/tutorial/variables/
and to determine your array size, lookie here http://stackoverflow.com/questions/3753 ... f-my-array
:D
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Free up processing, use 1 variable :)

Postby Hblade » Thu Jul 22, 2010 5:53 pm

Oh O.o


Thanks for the info, bee :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Free up processing, use 1 variable :)

Postby Fuzzy » Fri Jul 23, 2010 2:13 pm

I gotta agree with bee.

After all, you cant use things like % with reals. You also end up typing longer variable names, and as bee said, you waste a lot of space.

I would use that technique in very limited situations, and I applaud your thinking outside the box. I think you deserve a point for that.

What you could do is a mixture of that and an array of structures.

struct extra_actor_vars{
char name[];
int health;
float yourboat;
}

It could be quite elegant.
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: Free up processing, use 1 variable :)

Postby Hblade » Fri Jul 23, 2010 3:00 pm

Yeah :3
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest