Ref Variable

From GECK
Jump to: navigation, search

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.

See Also

  • IsFormValid - to check if a ref var is valid (holds either a Base Form or a Reference), which is useful in advanced scripting.
  • IsBaseForm - to check whether a ref var stores a base form, not reference.
  • IsReference - to check whether a ref var stores a reference, not base form.
  • IsActor - to check if a reference is an actor.
  • IsActorAlt - to check if a reference is an actor.
  • GetType - to check if a ref var refers is any particular type.