Time for action – Calling custom functions
We have our SpawnEnemy
function, and now we have an array of AwesomeEnemySpawner
actors in our AwesomeGame
class. Let's call SpawnEnemy
.
Let's add a new function to
AwesomeGame
calledActivateSpawners
:function ActivateSpawners() { local int i; for(i=0; i<EnemySpawners.length; i++) EnemySpawners[i].SpawnEnemy(); }
This will iterate through the
EnemySpawners
array and callSpawnEnemy
on each of them.Let's call our
ActivateSpawners
function fromPostBeginPlay
:simulated function PostBeginPlay() { local AwesomeEnemySpawner ES; super.PostBeginPlay(); foreach DynamicActors(class'AwesomeEnemySpawner', ES) EnemySpawners[EnemySpawners.length] = ES; ActivateSpawners(); }
Now,
PostBeginPlay
is getting an array of all of the spawners, and then calling the function that activates them.Compile the code and test. Now the log in
AwesomeEnemySpawner
'sPostBeginPlay
should show up:[0004.73] ScriptLog: SpawnEnemy called...