too many variables?

Game Editor comments and discussion.

too many variables?

Postby Fojam » Sun Mar 11, 2012 4:09 pm

how many variables is too many? if you have a lot of variables, will it slow down your game? and do actor variables take up more than regular variables?
I ask because i have a lot of variables in my game, and a large amount of them are actor variables. I am wondering if it would be better to try to thin down the amount of variables by combining variables such as moveLeft and moveRight into just move, where when it is -1 it is left and when it is 1 it is right
CLICK TO GIVE ME POINTS

My Latest Projects:
Super Smash Bros: viewtopic.php?f=6&t=12307 PLEASE help by making sprites!
User avatar
Fojam
 
Posts: 513
Joined: Thu Mar 19, 2009 10:02 pm
Location: under your bed!!!
Score: 69 Give a positive score

Re: too many variables?

Postby phyzix5761 » Sun Mar 11, 2012 4:34 pm

As you suggested, compressing two or more variables into one will save you allocated memory. But what you have to ask yourself is, "Are you already experiencing lag?" Your computer can process a lot. If you are having lag issues first check your collision methods, then your actors (are they out of view and doing nothing?) then finally come back to the variables.

Something that may also be worth seeing is your coding. Check to see if there are redundant statements of if any parts can be consolidated.
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

Re: too many variables?

Postby skydereign » Sun Mar 11, 2012 8:19 pm

You won't experience lag if you have too many variables. But, that doesn't mean you should make redundant variables. I can't think of any reason that you should have moveRight and moveLeft, if when one is equal to 1 the other is always equal to 0. Even then you can compress that into a single variable. This kind of optimizing makes your code a lot more manageable. And having less variables doesn't save you allocated space, unless you are using pointers and using dynamic memory allocation.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: too many variables?

Postby phyzix5761 » Sun Mar 11, 2012 8:43 pm

From what I've read Static, Auto, and Dynamic Variables are given allocated memory; Pointers as well.
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

Re: too many variables?

Postby skydereign » Sun Mar 11, 2012 8:50 pm

I'm talking about the stack versus the heap. The heap is where the user allocates memory via malloc/calloc/realloc. While technically you can say the local variables and the like are allocated out in the stack, usually the term allocated is reserved for the dynamic memory allocation functions (so anything involving the heap).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest