UnrealScript For Visual Basic Programmers
Introduction
If you've ever programmed in Visual Basic, you already know a lot of the basic concepts of coding (no pun intended). UnrealScript is a pretty full-fledged object-oriented language though, while Visual Basic's OOP support is more or less limited to the notion of having pre-defined objects (for instance, user interface elements) with some properties and methods. You can create and use your own classes in Visual Basic (in form of "class modules"), but the average Visual Basic programmer hardly ever will feel the need to do so.
A good read for getting into the notion of Object-Oriented Programming (OOP) is Object Oriented Programming Overview.
Familiar Concepts
Variables
In UnrealScript, all variables need to be predeclared using either var
(for class-level variables) or local
(for function-level variables). Variables declared on class level are globally accessible in that class. See UnrealScript Language Reference/Variables for details.
There's no "Variant" type in UnrealScript for variables that can hold any sort of data; variables are strongly typed, and you have to typecast them in most cases if you want to assign the value of a variable of one type to a variable of a different type.
Structured Programming
UnrealScript provides very similar means for structured programming (conditionals, loops) as Visual Basic. The following table lists corresponding idioms; see UnrealScript Language Reference/Program Structure for details of their syntax.
Statements in UnrealScript always end with a semicolon (;
), not (like in Visual Basic) with an end-of-line. You can therefore continue a statement in the next physical line just by not ending it with a semicolon; there's no need of an explicit line-continuation character like Visual Basic's underscore (_
).
You can make your UScript more readable with the continue keyword. With it, it makes easier (thus, a good practice) to go to the next loop item if a certain condition is not met.
Arrays
Arrays in UScript are easy, there is just 1 major thing to remember. Arrays start at 0! always. No wierd:
Dim SomeArray(2042 to 35930) AS Integer
just a simple:
var int SomeArray[420];
There are also Dynamic Arrays (they also ALWAYS start at 0).
Event-Driven Architecture
Everything in UnrealScript is driven by engine events, very similar to Visual Basic. The Actor class declares a variety of events that are inherited by Actor subclasses and called by the engine for every object of those classes. Sometimes you can even control how and when events are called; the Timer event, for instance, is controlled by the SetTimer function.
To have objects of your class do something, implement some or all of its events. You can, of course, also call functions from code executed for other objects, including objects of different classes. The functions of the Mutator class, for example, are actually called by other UnrealScript code.