Sniper's Paradise!


Variables in UnrealScript

This page will attempt to explain the basic facts about variables that are needed in order to get started. For a more in depth explanation when you are more confident with UnrealScript you can simply search the Unreal Wiki or UDN for any topics about Variables.

“Variables can appear in two kinds of places in UnrealScript: instance variables, which apply to an entire object, appear immediately after the class declarations. Local variables appear within a function, and are only active while that function executes.” UnrealScriptReference

Declaring Variables

Instance variables (also known as global variables) must appear at the top of the class before any function code, but after the class declaration.

Global variables must be declared with the “var” keyword. Global variables are available to any sub/child classes. A few examples of declaring global variables.

class MyVariables extends Actor;  //declare new class called "MyVariables" which extends the Actor class.

//The global variables must be declared after the class declaration but before any functions.
var int a;   //declare a global variable of type int (integer), and call it "a".
var string myword;   //declare a global variable of type string, and call it "myword".
var bool myfact;   //declare a global variable of type bool, and call it "myfact".
var Actor other;   //declare a global variable of type Actor, and call it "other".

function AnyFunction()
{
}

Local variables are declared within functions and can only be used within the function it was created in. These variables are not accessable anywhere else. Local variables must be declared with the “local” keyword. Local variables must be declated at the top of the function, before the functions code. A few examples of declaring local variables.

class MyVariables extends Actor;  //class declaration.

//global variables go here

function AnyFunction()
{
	local int b;  //declare a local variable of type int and call it "b".
	local string mylocalword;  //declare a local variable of type string and call it "mylocalword".

//function code goes after the local variables.
}

There are 8 very basic variable types supported by UnrealScript that you will be using a lot through out your coding. It’s important that you understand what they are and what they mean.

Variable Types

 

*information from the UnrealScriptReference.

 

Note – Use meaningful names for your variables.



Spam Killer

Back To Top
2005 Sniper's Paradise
All logos and trademarks are properties of their respective owners.
Unreal™ is a registered trademark of Epic Games Inc.
Privacy Policy
Website by Softly
Powered by RUSH