UT Tutorial: A simple mod - part 2

I've just read something on the speed of UScript. It seems that the usage of "foreach AllActors" is quite slow, because it iterates ALL actors. Since I just wanted to send a message to all players, and not to any other actor, there is a much faster way.

© Sybren Stüvel, written on 15 jan 2000


I assume you have read the "Simple Mod" tutorial. If not, do so now, then come back here.

The tutorial

The LevelInfo object contains a property, called PawnList. Since every pawn has a property 'nextPawn', it is possible to iterate through the players, without having to 'look' at all the other actors.

Here is an example, which can be used instead of line 15 and 16 of the Simple MOD tutorial:

for( P=Level.PawnList; P!=None; P=P.nextPawn )

If you want the players to hear a beep when receiving the message, change the second line to:


The second argument of the ClientMessage call is skipped. It is the (optional) type of the message. An empty type will simply put the message on the screen of the player. If you put 'Say' or 'TeamSay' here, the message will contain your name and current location. Thanks to Anthony Bowyer-Lowe (ynohtna@ynohtna.org) for this info. The third argument 'true' indicates that is should play a beep :-).

You can also use the BroadcastMessage function, located in the Actor-class. You can call it like this: BroadcastMessage("Your message here",True). It will do the same as the above, but it will only send a message if it is allowed according to the game rules defined in the GameType class.

I hope your mods can become somewhat speedier now you know this!