Difference between revisions of "Reference Variables"
imported>Jduvall |
imported>Jduvall |
||
Line 59: | Line 59: | ||
CAVEAT: Objects created by leveled lists do not process in low, if you set a reference variable from a leveled list, if your script tries to refer to that reference variable when that actor isn't loaded, bad things will happen. So don't ever do a "set myRefVariable to myXmarker.placeAtMe myLeveledList". Instead create an if-then section in a script which checks the player level, pick an appropriate base object for the players level, then do a "set myRefVariable to myXmarker.placeAtMe SpecificBaseObjectID". | CAVEAT: Objects created by leveled lists do not process in low, if you set a reference variable from a leveled list, if your script tries to refer to that reference variable when that actor isn't loaded, bad things will happen. So don't ever do a "set myRefVariable to myXmarker.placeAtMe myLeveledList". Instead create an if-then section in a script which checks the player level, pick an appropriate base object for the players level, then do a "set myRefVariable to myXmarker.placeAtMe SpecificBaseObjectID". | ||
CAVEAT 2: You can not pass reference variables IN OTHER SCRIPTS as parameters to functions that take references. You must first set a local reference variable. For example: "myCharacterRef.look MyQuestScript.myReferenceVariable" will fail whereas "myCharacterRef.look myReferenceVariableDeclaredInThisScript" will work just fine | CAVEAT 2: You can not pass reference variables IN OTHER SCRIPTS as parameters to functions that take references. You must first set a local reference variable. For example: "myCharacterRef.look MyQuestScript.myReferenceVariable" will fail whereas "myCharacterRef.look myReferenceVariableDeclaredInThisScript" will work just fine. So in the local script just declare a "ref myReferenceVariableDeclaredInThisScript" and then set it to the external one "set myReferenceVariableDeclaredInThisScript to MyQuestScript.myReferenceVariable", and use the local one. | ||
[[Category:Variables]] | [[Category:Variables]] |
Revision as of 16:51, 24 May 2006
Like other variables, reference variables must be declared before they can be used:
ref refVarName
You can use a reference variable anywhere you could use an object reference. Uninitialized reference variables act as if they referred to the scripted object itself; otherwise a reference variable acts just like any other reference.
A reference variable whose object is not in memory (such as a static object after the player leaves that object's cell) is treated as uninitialized.
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 != 0
To check if a ref variable is another reference (in this example the player):
if myReferenceVariable == player
Or not another reference:
if myReferenceVariable != player
Example:
scn TheMastersSword ; Whoever equips it gets +50 to blade ref UserRef begin OnEquip set UserRef to GetContainer UserRef.Modactorvalue blade 50 end begin OnUnEquip set UserRef to GetContainer UserRef.Modactorvalue blade -50 end
CAVEAT: Objects created by leveled lists do not process in low, if you set a reference variable from a leveled list, if your script tries to refer to that reference variable when that actor isn't loaded, bad things will happen. So don't ever do a "set myRefVariable to myXmarker.placeAtMe myLeveledList". Instead create an if-then section in a script which checks the player level, pick an appropriate base object for the players level, then do a "set myRefVariable to myXmarker.placeAtMe SpecificBaseObjectID".
CAVEAT 2: You can not pass reference variables IN OTHER SCRIPTS as parameters to functions that take references. You must first set a local reference variable. For example: "myCharacterRef.look MyQuestScript.myReferenceVariable" will fail whereas "myCharacterRef.look myReferenceVariableDeclaredInThisScript" will work just fine. So in the local script just declare a "ref myReferenceVariableDeclaredInThisScript" and then set it to the external one "set myReferenceVariableDeclaredInThisScript to MyQuestScript.myReferenceVariable", and use the local one.