UnrealScript is the object-oriented language used in Unreal and its brethren.

Its syntax is similar to C++, with some notable differences. The differences make it well-tailored to game design, if the mod programmer doesn't mind the approximate 20x performance hit compared to plain C++.

Some of the features of UnrealScript tailored to games:

States: Objects (referred to as actors within UnrealScript) can specify separate states. Functions can be defined to be local to one state. States can be changed at any time using the GotoState function. States make code much cleaner - instead of several "if"s in every message handler, the programmer can simply group functions into one state. Examples of states are "PlayerWalking", "Fire" (for weapons), and "Idle" (when objects aren't doing anything).

Foreach: This iterator command takes a function that iterates over actors in a level. The iterator functions are AllActors (all actors in the level), ChildActors (actors owned by the current actors; e.g. weapons owned by a player), BasedActors (all actors on top of this actor spatially), TraceActors (all actors in a line), RadiusActors (all actors in a radius), and VisibleActors (all actors in a radius visible to a certain location).

Useful 3D base classes: Cast a vector to a rotator, using the "rotator (v)" syntax, and the rotator automatically faces the vector. No functions are necessary, as the operators are overloaded. Another example: Computing the dot-product of a vector is as simple as "vect1 dot vect2" - no strange syntaxes.

Default properties: Properties of objects can be set with UnrealEd or as they are spawned manually - but, with the hundreds of properties available, there needs to be some way to set default properties. The cool thing about UnrealScript default properties is that they can be dynamically modified at run time, so that, for instance, I could say that all Rocket Launcher ammo gives 100 rockets from this point on. This wizardry would be performed using the ".default" syntax ("class'RocketPack'.default.AmmoAmount = 100;").

Easy network replication: Network replication can be tricky to understand. However, it's simple to code in UnrealScript. Each object has a "replication" clause that may be attached to it. I'm not going to go into the details here because it could fill up an entire node, but suffice it to say that Unreal handles replication easily.

UnrealScript does have its disadvantages, though:

Some strange syntaxes: do...until instead of do...while? There are some other funny idiosyncrasies, such as the parser's inability to eat whitespace in the defaultproperties section (e.g. AmmoAmount=20 works, but AmmoAmount = 20 doesn't).

More to learn: With Quake and other engines, the aspiring mod author doesn't have to learn a whole new language. UnrealScript takes time to master.

Sloooow: UnrealScript is compiled (using ucc), but it is still slow. Quake 3's QVM files are quite a bit faster. The trick to writing fast UnrealScript code is to minimize loops and only execute code in response to events. Quake programmers have more flexibility in their coding practices.

Lack of documentation: Hope you like Chimeric and the official Unreal site, because that's all there is. Most of UnrealScript (beyond the basics) has to be figured out on one's own.

UnrealScript is a powerful language with its own advantages and disadvantages. I prefer it over the Quake C code, but to each his own. Even if you are a Quake addict, it's worth a look.

Log in or register to write something here or to contact authors.