• Forum
  • Lounge
  • Initializing variables too much...or not

 
Initializing variables too much...or not?

Hello everyone. I've been coding a lot of games lately and have fell into the habit of initializing A LOT of variables at certain points when I need a specific task done such as firing off two or more bullets or opening up a double jump after the character has found that secret token. The variables have nothing to do with anything except to have an affect on one little tiny piece of code. It gets to the point sometimes that it's somewhat confusing but it's doable and it always works. I was wondering do any of you do the same thing and would this be acceptable in the industry as my code would have to be "deciphered" by another programmer?
As long as you properly comment what exactly each set of variables is for, all is good.

Better, though, would be to encapsulate all that stuff in a managed class.

controller maintains list of objects being used
when object is finished, it asks controller to delete it
spawn new object for each action, and add it to the controller

Hope this helps.
Thanks. Nice to know I'm not headed down the wrong path
Topic archived. No new replies allowed.