Time for action – Using Clock and UnClock
Let's run a little test with BrokenActor
to see how to use these two functions.
Open
BrokenActor.uc
in ConTEXT.We'll use
PostBeginPlay
for this. Let's write it like this:function PostBeginPlay() { local int i; local float StopWatch, Size; local vector A, B; Clock(StopWatch); for(i=0; i<1000; i++) { A = VRand() * 1000; B = VRand() * 1000; Size = VSize(A - B); } UnClock(StopWatch); `log("Time taken to execute:" @ StopWatch); }
What we're doing here is running a loop 1000 times. Each time we take two vectors,
A
andB
, and randomize them. Then we calculate the distance between them withVSize
. We use a float calledStopWatch
in theClock
andUnClock
functions, then log the value so we can see how long it took to run the loop.Compile the code. We'll get a warning about
Size
, but we'll ignore it for this test.Run the game, then exit and take a look at the log:
[0005.32] ScriptLog: Time taken...