View Single Post
Old 09-29-2007, 03:43 AM   #3
Optimus_P-Fat
Insider

 
Optimus_P-Fat's Avatar
 
Join Date: Jan 2006
Location: New Jersey
Posts: 3,633
Default
Reply With Quote


How to declare variables in UnrealScript

DECLARING your variable is the first step towards being able to use it in you script logic. Variables are ALWAYS declared at the top of your class file, underneath the declaration of your class (for our purposes now, this is the first line of code in the file - it has the name of your class in it, more on this in a later lesson). They can also be declared LOCALLY in FUNCTIONS, but right now, we will not touch on that until a future lesson on FUNCTIONS. The way you declare a variable is as such:

var<group> <modifiers> <type> <name>;

The keyword var tells the code you are declaring a variable for use later.

The <group> portion is optional - if you specify a name in parenthesis here, you are telling Unrealscript you want this variable to show up in UEd under that group name. If you put empty parenthesis here, you are saying "display this in UEd, but make it part of the default group", and finally if you omit the <group> portion altogether, you are saying that this variable is for internal script usage only and should NOT be exposed through UEd.

The <modifiers> section is 0 or more keywords that apply advanced handling to the variable. For our current situation, we will not discuss these here, and you are not REQUIRED to add modifiers to declare a variable (although you will need some to do specific things with the variable later - but that is not important in this lesson)

The <type> field is a single keyword and is REQUIRED in your variable declaration. This is where you tell the code what TYPE of variable this will be. I will discuss some of the simple types here. For a more complete list of variable TYPEs, please go here: http://wiki.beyondunreal.com/wiki/Variable_Type

- bool - this is a boolean value. It's ONLY possible values are true or false.

- int - this is an integer value. It's possible values are whole numbers ranging from -2147483648 to 2147483647.

- byte - this is a special kind of integer value - it is a single byte. As such, it's values range from 0 to 255.

- float - this is a floating point decimal value - i.e. numbers such as 2.5, 4.83, etc.

- string - a STRING in programming is a 'string' of characters grouped together and treated as a single entity or value. Strings in UnrealScript as specified by wrapping them in double quotes, like such: "my string value!", "whoopie doo da", or "she said @$@!" In order to have a double quote in your string, you must do something known as ESCAPING the character with a backslash, like so: "This: \" is a string with a quote in it!". As you may have guessed, getting a backslash in the string requires the same procedure, as such: "This is a backslash: \\". To get a newline, you can use \n.

There are other types you may use, but for this tutorial we will stick with the basics. You may read about the other types in the link I provided above.

The <name> field is also REQUIRED, and is the name that you are giving to the variable. As described above, it can contain letters, numbers, and the underscore, but may NOT begin with a number.

Finally, there is the important SEMI-COLON. The semi-colon is the way you can tell the code, "this line is complete"- think of it as the period to a sentence in code-land. All code statements must end with a semi-colon.

Example variable declarations:

var int FingerCount;
var() string MyMapName;
var(Display) float DrawScale;

In the examples above, the first line declares an integer type variable, named FingerCount, that will NOT be visible in UEd. The second line declares a string variable, called MyMapName that WILL be accessible in UEd in the default group for your object. The third line declares a float type variable named DrawScale that will show up in UEd under the Display group.
__________________

http://www.p-fat.net/
Optimus_P-Fat is offline