Time for action – Misleading errors
Sometimes error messages might seem a little misleading, as we'll see in this next experiment:
Let's rewrite our
PostBeginPlay
function. We'll leave in ourMyInt
variable and use it for this experiment:simulated function PostBeginPlay() { if(UTGame(WorldInfo.Game != none) MyInt = UTGame(WorldInfo.Game).DefaultMaxLives; }
Seems fine, but when we try to compile we get this error:
[0004.84] Log: R:\UDK\UDK-AwesomeGame\Development\Src\BrokenGame\Classes\BrokenActor.uc(8) : Error, Bad or missing expression for token: UTGame, in 'If'
What could this mean? It seems to be telling us that it doesn't know what
UTGame
is, even though it's a valid class. If we take a closer look at our if statement, we can see the problem:if(UTGame(WorldInfo.Game != none)
I'm counting two open parentheses, but only one closed one. If we take the
if
part out of this line and examine it separately:UTGame(WorldInfo.Game != none)
To the compiler, it looks like we're trying...