Difference between revisions of "Variables and Properties"
→Notes
imported>GigaPoint |
imported>Marth (→Notes) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 179: | Line 179: | ||
==Getting Properties From Any Other Script== | ==Getting Properties From Any Other Script== | ||
You can | You can access the properties of any script attached to any object not just those attached to quests. But you will be accessing a specific script attached to a specific object. | ||
'''Example:''' | |||
<source lang="papyrus"> | <source lang="papyrus"> | ||
ScriptName ScriptA extends | ScriptName ScriptA extends ObjectReference | ||
int Property | int Property count Auto | ||
float Property | float Property weight Auto | ||
</source> | |||
If both scripts are attached to the same game object (Quest, Perk, ObjectReference, etc.) accessing the variables from the other script is simply a matter of casting self to the correct type. | |||
< | '''Example:''' | ||
<source lang="papyrus"> | |||
ScriptName ScriptB extends ObjectReference | |||
Event OnInit() | |||
ScriptA me = self as ScriptA | |||
me.count = 1 | |||
me.weight = 12.9 | |||
(self as ScriptA).count += 7 ; this in-line method works too | |||
<source | EndEvent | ||
</source> | |||
If the other script is attached to some other object then you'll need a way to access that object. The most common way is a property but you might also get access through some Event argument instead. | |||
'''Example:''' | |||
<source lang="papyrus"> | |||
ScriptName ScriptB extends ObjectReference | |||
ScriptA Property remoteObject Auto | |||
Event OnInit() | Event OnInit() | ||
remoteObject.count = 1 | |||
remoteObject.weight = 12.9 | |||
EndEvent | |||
Event OnActivate(ObjectReference akActionRef) | |||
if (akActionRef as ScriptA) | |||
(akActionRef as ScriptA).count += 7 | |||
endif | |||
EndEvent | |||
</source> | |||
For a list of objects you can use as a type that are already within the game, visit the [[Script Objects]] page. | For a list of objects you can use as a type that are already within the game, visit the [[Script Objects]] page. | ||
Line 258: | Line 249: | ||
==Notes== | ==Notes== | ||
*The list of properties in properties dialog is only updated after adding a new property or after compiling the script with the build-in editor. | *The list of properties in properties dialog is only updated after adding a new property or after compiling the script with the build-in editor. | ||
*You should avoid adding or removing Properties to a base item's script if one or more of its child ObjectReference's is already baked into a current save game. | |||
==See Also== | ==See Also== |