View Full Version : Global variables???

Euphoric Beaver
29th Oct 2001, 11:02 AM
Right, say I've declared this at the top.
var int cat
Now how would I set another variable called dog to make it equal cat? BTW they are in seperate files.

Also I've seen variables declared with a var() aswell as var.
What does the () mean?

29th Oct 2001, 11:25 AM
() means that it's an editable Variable. Editable Var means, it shows up in the object's properties in the Ed, where the mapper can change its value. Btw, the default value an editable Var shall have is declared in the defaultproperties.
This way you can also give a group to a Var, e.g.
Var (group) bool bSomeVar;
examples of groups like that would be "Advanced", "collision"...

29th Oct 2001, 11:38 AM
Originally posted by Ciced
Right, say I've declared this at the top.
var int cat
Now how would I set another variable called dog to make it equal cat? BTW they are in seperate files.

seperate files? you mean they're in seperate classes?
If you have an instance of the first class, you can grab its value of the cat variable with myObject.cat .
You can get default variables from the abstract class itself too:

Euphoric Beaver
29th Oct 2001, 12:22 PM
Thanks people. :D

Euphoric Beaver
29th Oct 2001, 12:30 PM
Oh and does this mean you can set variables from other seperate classes?

So to set my cat variable to the same as the dog variable from a differant class and perhaps divide it by 2?

cat = (mypackage.dog / 2);

29th Oct 2001, 02:53 PM
yes, but be careful not to confuse a package and a class :)
cat = class'MyPackage.MyClass'.default.dog / 2

that will get you the default value of dog.

Euphoric Beaver
29th Oct 2001, 03:04 PM
Yes I see. :D

What if I wanted to divide my original default property by 2, assuming there in the same class.
Would this be it?

cat = class'MyPackage.MyClass'.default.cat / 2

Or is there a shortcut because your working out the variable in the same class? Like this?

cat = cat / 2

Would they produce the same result?

29th Oct 2001, 03:40 PM
Have you got Tim Sweeney's documentation on UnrealScript? Tat explains some of this.

Now, be sure not to confuse the roles of a class C, and an object O belonging to class C. 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!

code is execute (usually) by an object of a class. That object has its own variables, that initially are set to the defaults.
So your script already knows what cat is. If you want to change the value at some point in the script, then something like
cat = cat /2 ;
is fine.
I think the first option you gave would produce the same thing, but it's the long way round!

Euphoric Beaver
29th Oct 2001, 03:55 PM
Okeydidels. :D Thanks. :D Think that's all. :)

Euphoric Beaver
1st Nov 2001, 07:57 AM
Oh and one more thing?

Okay, say I made a global variable that in the code = the Player Pawns fatness.
Does the global variable only have one instance of it? Ie it changes for each pawn that activated the code.
Or does it have a variable for each pawn that activated the code?
What if I used a local variable instead?

1st Nov 2001, 09:17 AM
AFAIK, there are no actual global variables in UnrealScript.
What you mean (I think) is the distinction between class variables and local variables in a function.

Pawns don't activate class code -- they ARE class code, in a way. Each pawn you see is an an instance of a class. Every instance of a class has its own values for variables.
So for example, the class for players has a class variable for the player's health. Each particular player is an instance of that class, and each player's health is particular to him or her.

You can give class variables a default value, and then that will be the same for all instances of that class.
You can also declare constants for a class, which do not change.