Time for action – Using static functions
For this experiment let's use our AwesomeWeapon
class.
The first thing we need to do is delete the weapon spawner from our test level. We don't want any instances of an
AwesomeWeapon
class in the game. This will help us better understand what the static function is doing.Now let's write a static function in our
AwesomeWeapon
class:static function float GetDefaultFireRate() { return default.FireRates[0]; }
We're also giving this function a return value, which will tell us what the default firing rate of the weapon class is.
Now let's call the function from our
Upgrade
exec function inAwesomePlayerController
:exec function Upgrade() { local float f; f = class'AwesomeWeapon_RocketLauncher'.static.GetDefaultFireRate(); `log(f); if(Pawn != none && AwesomeWeapon(Pawn.Weapon) != none) AwesomeWeapon(Pawn.Weapon).UpgradeWeapon(); }
Remembering inheritance, our rocket launcher inherits the static function so we can call it on...