Ref Variable

Revision as of 06:57, 14 August 2014 by imported>Odessa (Importantly, ref vars can store base forms as well as references)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

In the GECK, a ref variable may store either a reference or a base form

Like other variables, reference variables must be declared before they can be used:

ref   refVarName  

Stored References

You can use a ref variable that stores a reference anywhere you could use an object reference. Uninitialized reference variables hold a value of 0, and will cause a script to silently stop running if used to call a reference function; otherwise a ref variable storing a reference acts just like any other reference.

You set reference variables using the set command, like other variables. Normally, you will want to use a reference variable function, which returns a formID. For example:

set myRef to GetContainer  

Like other variables, you can set a reference variable on another scripted object:

 set BobRef.myRef to GetSelf   

To check if a ref variable is unset:

if myReferenceVariable == 0

To check if a ref variable is set:

if myReferenceVariable

To check if a ref variable is another reference (in this example the player):

if myReferenceVariable == PlayerREF

Or not another reference:

if myReferenceVariable != PlayerREF

Stored Base Forms

You may store a base form in the same way:

ref MyWeapon
set MyWeapon to Weap10mmPistol

Beware that this is still a base form and may not be used as the calling reference to functions that allows this syntax, although it may be passed as the target if the function permits this.