Difference between revisions of "Variables and Properties"

449 bytes added ,  17:22, 14 February 2012
m
→‎From Within a Magic Effect Script: Formatting tweaks, spelling error fix, and additional info added to examples.
imported>Cipscis
m (→‎Declaring Variables: Fixing grammar mistake - it's -> its)
imported>Delfofthebla
m (→‎From Within a Magic Effect Script: Formatting tweaks, spelling error fix, and additional info added to examples.)
Line 145: Line 145:
All scripts can access other scripts, however they can ''only'' access the script's properties.
All scripts can access other scripts, however they can ''only'' access the script's properties.


Let's look at an example where a spell accesses a quest's properties:
 
Let's look at an example where a scripted spell accesses a quest's properties:
<source lang="papyrus">
<source lang="papyrus">
Scriptname myQuestNameScript extends Quest
Scriptname myQuestNameScript extends Quest


Int Property PublicInt Auto ; This value is defined as a property and can be accessed from outside this script
Int Property PublicDamage Auto ; This value is defined as a property and can be accessed from outside this script


Int PriviteInt = 144 ; This value is private to the script and cannot be accessed from outside this script
Int PriviteDamage = 30 ; This value is private to the script and cannot be accessed from outside this script


Function DamageTarget(Actor akTarget)
Function DamageTargBasedOnPublic(Actor akTarget)
;This code will damage the akTarget for PublicInt damage
akTarget.DamageAV("Health", PublicInt)
EndFunction
 
Function DamageTargBasedOnPrivate(Actor akTarget)
;This code will damage the akTarget for PublicInt damage
;This code will damage the akTarget for PublicInt damage
akTarget.DamageAV("Health", PublicInt)
akTarget.DamageAV("Health", PublicInt)
Line 159: Line 165:
</source>
</source>


Now that we have defined our quest script and created an accessable property, we can control it from the outside.
 
Now that we have defined our quest script and created an accessible property, we can control it from the outside.
<source lang="papyrus">
<source lang="papyrus">
Scriptname mySpellEffectScript extends activemagiceffect
Scriptname mySpellEffectScript extends activemagiceffect
Line 166: Line 173:


Event OnEffectStart(Actor akTarget, Actor akCaster)
Event OnEffectStart(Actor akTarget, Actor akCaster)
myQuestRef.PublicInt = 20 ;Set the Public Int to 20
myQuestRef.PublicInt = 20 ; This will change the damage for the DamageTargBasedonPublic Function
myQuestRef.DamageTarget(akTarget)
myQuestRef.DamageTargBasedOnPublic(akTarget) ; You can manipulate this damage by changing PublicDamage Prior to calling it
myQuestRef.DamageTargBasedOnPrivate(akTarget) ; This will always do 30 damage unless the quest changes the private variable
EndEvent
EndEvent
</source>
</source>


=Getting Properties From Any Other Script=
=Getting Properties From Any Other Script=
Anonymous user