Basic - General Object Oriented Programming and Unrealscript

If you want to look at more basic ideas like variables and control statements, see the previous tutorial. I would define object oriented programming by way of analogy or comparison more than a strict definition, because I think it captures what it is actually all about. Object Oriented Programming, (OOP) is conceptualized in objects, simple as that. Think of any real life object. Suppose I had a sword. If you were to describe it to me, would you simply say it's a sword? Recall in writing how there are often instances where authors describe an object --say they are describing this sword-- and they tell of its length, its sharpness, its shape, its colors, what steel and material it is composed of, and so forth, and further name the sword, like, a broadsword. Then later in the book they no longer say, "the sword which is four feet long, has a dark handle, is made of high carbon steel with a curved handle," and so forth, instead, they simply refer to it as a broadsword, and your mind can recall what that broadsword is by its description. The same occurs in Object Oriented Programming. I can describe an object once, and then refer to that object without ever having to describe it again, but define its particulars.

 

I know this is touching on Unrealscript but I would also like to bring in some C++ just to show the other side of the issue. In C++ a class is basically a prototype for an object. It is the description of the sword as previously discussed.

Here I describe the sword, or make the class:

class Broadsword

{

int length; //length, sharpness, etc. properties of the sword

int sharpness;

string steeltype;

bool drawn;

 

Broadsword(string steeltype);

~Broadsword();

 

int attemptDraw(); //"actions" aka methods

int strike();

};

With this I can later add more broadswords when I prefer, and not have to redefine or reuse the same approach.

 

Let's recall how it is often the case that in some hierarchical scripting languages like Papyrus or Unrealscript, we have parent and child classes, the syntax of which is something like

class ChildClass expands ParentClass;

Now note that every child inherits the properties of its parent class. If the parent class has a variable boolean bNew, the child will have the same bNew boolean. This is very important in approaching Unrealscript as well. How about creating a subclass of the SkaarjTrooper in Unreal Editor by going to the Actor Browser, expanding Pawn -> ScriptedPawn -> Skaarj and right clicking on SkaarjTrooper to make a new class, which you should package as MyLevel. Now double click on the SkaarjTrooper script --not yours. Under the exec directives (the gray code) you'll find a variable:

var() class<weapon> WeaponType;

Now go to your SkaarjTrooper class, and right click on it in the Actor Browser, and click on default properties. Then expand SkaarjTrooper and you'll find the WeaponType variable inside. You can change your variable's default setting and modify your SkaarjTrooper as you'd like, and it will inherit the behavior and properties of its parent class. In the next tutorial we'll actually be writing a function and looking and what we can do more than just changing variable values.