Like other variables, reference variables must be declared before they can be used:
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.
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:
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.