View Single Post
  #5  
Old 09-06-2011, 03:31 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
I picked a bad choice of words before instead of 'use functions properly' I was trying to say 'use functions to your advantage':

PHP Code:
//#CLIENTSIDE
function onKeyPressed() {
  if (
keydown(0)) {
    
doKeyDownZeroStuff();
  }
  else if (
keydown(1)) {
    
doKeyDownOneStuff();
  } 
}

function 
doKeyDownZeroStuff() {
  
// code...
}

function 
doKeyDownOneStuff() {
  
// code...

Obviously give the functions meaningful names i.e:

PHP Code:
//#CLIENTSIDE
function onKeyPressed() {
  if (
keydown(5)) {
    
doAttack();
  }
}

function 
doAttack() {
  
// attack code here...

It increases the maintainability of your code and allows you to separate the different pieces of logic into much more manageable bites.

I.e: In my example above I have the keyboard controls logic in onKeyPressed and my call to doAttack allows me to store all my attacking logic in doAttack.
__________________
Quote:
Reply With Quote