- Admin
- #151
- Joined
- Jul 9, 2006
- Messages
- 6,904
- Reaction score
- 71
You're thinking of it in a very narrow manner. Examples:
Single-use situation:
Multi-use situation:
Suffice it to say, don't call a function that's going to return the same information every time (especially when it's cpu intensive), and, if you have a section of code that will be used more than once, write a function so that you don't have to copy paste the code. Functions are also best for keeping the code clean looking >_>
Single-use situation:
Code:
float monsMaxHP = pMons->MaxHP();
(lots of things involving monsMaxHP)
Multi-use situation:
Code:
foreach( i , EntArraySize )
{
CBaseEntity *pEnt = EntArray[i];
if( DistanceFromEnt( pEnt ) <= AOESize ) DoDamage( ... );
}
Suffice it to say, don't call a function that's going to return the same information every time (especially when it's cpu intensive), and, if you have a section of code that will be used more than once, write a function so that you don't have to copy paste the code. Functions are also best for keeping the code clean looking >_>