Time for action – Using Actors as local variables
Let's take a look at the PostBeginPlay
function from our AwesomeGame
class:
simulated function PostBeginPlay() { local AwesomeEnemySpawner ES; super.PostBeginPlay(); GoalScore = EnemiesLeft; foreach DynamicActors(class'AwesomeEnemySpawner', ES) EnemySpawners[EnemySpawners.length] = ES; ActivateSpawners(); }
Here we're declaring a local variable of type AwesomeEnemySpawner
and giving it a name of ES (short for Enemy Spawner). Near the end of the function we use the foreach
iterator to find all of the AwesomeEnemySpawners
in the map. The way the iterator works is that it gives us a reference to all of those actors it can find, as well as subclasses of that class, one at a time instead of in an array. To be able to sort through them we need to store the reference in a variable, so it makes sense to use a local variable here. We then take that temporary reference and assign it to the end of our more permanent array...