| Home Page | Recent Changes | Preferences

Peppers And Pepper Grinders

To give a really shaky analogy, a class is like a pepper grinder, and an object is like pepper. You can use the pepper grinder (the class) to create pepper (objects of that class) by turning the crank (calling the Spawn function)... but, a pepper grinder (a class) is not pepper (an object belonging to the class), so you must not try to eat it! – Tim Sweeney in the UnrealScript Language Reference

UnrealScript's Variable Syntax lets you define variables to hold numbers, strings, vectors and so on. It also lets you define variables that "point to" objects and classes. At this point, like Tim Sweeney says, it's important not to get confused between the two.

Referring to an object

You're probably comfortable with the idea of giving a variable type, like this:

var float theNumber;

That just says theNumber is a variable that holds a number. But you can also do things like:

var Actor theThing;

This variable is an actor. Now comes the tricky part: it might be a specific actor that exists in the game, or it might not. One specific actor in the game can have lots of variables that indicate it – this is no different from having many float variables all set to '3', if you think about it.

For a specific actor, you might have something like this:

// from UT2003's Actor:
event ZoneChange( ZoneInfo NewZone );

The NewZone variable is of class ZoneInfo – it is a ZoneInfo, and you can expect to access any ZoneInfo properties by saying NewZone.property. It's a specific ZoneInfo in the current game, namely, the one that the actor has just entered.

On the other hand, when using Iterators, this construction is common:

function PostBeginPlay()
{
    local Pawn OnlyThisPawn;

    foreach AllActors(class'Pawn', OnlyThisPawn)
    {
        break;
    }
}

The variable OnlyThisPawn is a Pawn. When we declare it, is doesn't actually hold anything – it doesn't point to a real Pawn in the game. But within the foreach loop, we'll be successively making it point to actual Pawns in the game. This is no different to setting a numerical variable to many different values. Of course, when you set theNumber to 387, you can't do much with that apart from know that it's 387. But when OnlyThisPawn points to a particular pawn in the game, you can then access that particular pawn's properties and methods.

Referring to a class

// from UT2003's Actor:
event TakeDamage( int Damage, Pawn EventInstigator, vector HitLocation, vector Momentum, 
  class<DamageType> DamageType);

The last variable, DamageType is a class variable. Because the word "DamageType" is used twice, this is going to get confusing, so let's alter this slightly:

// from UT2003's Actor:
event TakeDamage( class<DamageType> Ouch);

Now Ouch is a variable that indicates a class. The <DamageType> part is a "limiter": it tells us that Ouch must be a DamageType, or a subclass of DamageType.

But the variable Ouch is still empty. How might we put an actual class in there?

var class<DamageType> Ouch;
Ouch = class'BiteMe';

Referring to a resource

Sound'WeaponSounds.LinkGun.SwitchToLinkGun'

Useful functions

See Global Functions:

  • IsA
  • ClassIsChildOf

Related Topics

Discussion

SuperApe: Part of the restaurant or food prep family of beginning UScript pages. :) Needs linkages from relevant hubs for more use.

T-1: This probably needs a merge with Object Oriented Programming Overview


Category Tutorial

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

FAQs

Help Desk

Mapping Topics

Mapping Lessons

UnrealEd Interface

UnrealScript Topics

UnrealScript Lessons

Making Mods

Class Tree

Modeling Topics

Chongqing Page

Log In