Global variables???

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

RestInPieces

New Member
Sep 20, 2001
65
0
0
www.Creep-World.net
() 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"...
 

tarquin

design is flawed
Oct 11, 2000
3,945
0
36
UK
www.planetunreal.com
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:
Code:
class'Spotlight'.default.LightBrightness
 

Euphoric Beaver

impeccably groomed
Apr 19, 2001
3,158
0
0
Great Britain
www.euphoric-beaver.me.uk
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?

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

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

Code:
cat = cat / 2

Would they produce the same result?
 

tarquin

design is flawed
Oct 11, 2000
3,945
0
36
UK
www.planetunreal.com
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

impeccably groomed
Apr 19, 2001
3,158
0
0
Great Britain
www.euphoric-beaver.me.uk
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?
 

tarquin

design is flawed
Oct 11, 2000
3,945
0
36
UK
www.planetunreal.com
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.