Difference between revisions of "Variables and Properties"

1,153 bytes added ,  14:38, 11 December 2013
imported>Scrivener07
imported>GigaPoint
Line 180: Line 180:
==Getting Properties From Any Other Script==
==Getting Properties From Any Other Script==
You can use the above example regarding the Magic Effect script as a basis for your script. You must define a property in your script, with the "Type" of your object you are wishing to access. If your object has a custom script, define the type as your object's script name. Be careful not to declare it as the object's name. All objects can have multiple scripts, so you must specify the ''script name'' you want to access.
You can use the above example regarding the Magic Effect script as a basis for your script. You must define a property in your script, with the "Type" of your object you are wishing to access. If your object has a custom script, define the type as your object's script name. Be careful not to declare it as the object's name. All objects can have multiple scripts, so you must specify the ''script name'' you want to access.
<br>'''Example:'''
<source lang="papyrus">
ScriptName ScriptA extends Quest
int Property intProperty Auto
float Property floatProperty Auto
GlobalVariable Property gvProperty Auto
Shout Property shoutProperty Auto
</source>
Since we want to get ScriptA's properties and/or change them, we'll set up another script called ScriptB:
<source lang="papyrus">
ScriptName ScriptB extends Quest
int iVar
float fVar
GlobalVariable gVar
ScriptA property MyScriptProperty
ScriptA Function Get()
If !GetData
GetData = True
ReturnVal = (Self as Quest) as ScriptA
EndIf
return ReturnVal
EndFunction
Function Set(ScriptA NewValue)
If !SetData
SetData = True
ReturnVal = NewValue
EndIf
EndFunction
Endproperty
Bool GetData = False
Bool SetData = False
ScriptA ReturnVal
Event OnInit()
        MyScriptProperty.intProperty = 10    ;sets intProperty to 10
        MyScriptProperty.floatProperty = 5.5  ;sets floatProperty to 5.5
        MyScriptProperty.gvProperty.SetValue(10)  ;sets gvProperty to 10
        MyScriptProperty.gvProperty.GetValue()    ;returns 10
        MyScriptProperty.shoutProperty   
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.


'''See Also: [[Function_Reference#Accessing_Functions_From_Other_Scripts|Accessing Functions From Other Scripts]]'''
'''See Also: [[Function_Reference#Accessing_Functions_From_Other_Scripts|Accessing Functions From Other Scripts]]'''


==Warnings==
==Warnings==
Anonymous user