Difference between revisions of "Ref Variable"

From the Fallout3 GECK Wiki
Jump to navigation Jump to search
imported>Odessa
(Importantly, ref vars can store base forms as well as references)
 
imported>Odessa
(+see also for useful ref var functions)
 
Line 53: Line 53:
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.
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==
*[[IsReference]] - to check whether a ref var stores a reference, not base form.
*[[IsActor]] - to check if a <b>reference</b> is an actor.
*[[GetType]] - to check if a ref var refers is any particular type.
*[[IsFormValid]] - to check if a ref var is valid, which is useful in advanced scripting.
[[Category:Commands]]
[[Category:Commands]]
[[Category:Scripting]]
[[Category:Scripting]]
[[Category:Variables]]
[[Category:Variables]]

Latest revision as of 07:39, 9 September 2014

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[edit | edit source]

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[edit | edit source]

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[edit | edit source]

  • IsReference - to check whether a ref var stores a reference, not base form.
  • IsActor - to check if a reference is an actor.
  • GetType - to check if a ref var refers is any particular type.
  • IsFormValid - to check if a ref var is valid, which is useful in advanced scripting.