What's your function?
In a nutshell, a function is a block of code written to perform a specific task that can be called as many times as we need from other parts of our program. As an example, if we had a function called EatAnApple
, it would be like this:
var int i, NumberOfSlices; function EatAnApple() { WashApple(); NumberOfSlices = SliceApple(); for(i=0; i<NumberOfSlices; i++) ChewAppleSlice(); ThrowAwayAppleCore(); }
Instead of having to write out each line every time we want to eat an apple, we just call the EatAnApple()
function. As a more practical example from our own code, let's take a look at our AwesomeWeapon
:
function UpgradeWeapon() { if(CurrentWeaponLevel < MAX_LEVEL) CurrentWeaponLevel++; FireInterval[0] = FireRates[CurrentWeaponLevel - 1]; if(IsInState('WeaponFiring')) { ClearTimer(nameof(RefireCheckTimer)); TimeWeaponFiring(CurrentFireMode); } AddAmmo(MaxAmmoCount); }
Instead of having all of...