Difference between revisions of "Variables and Properties"
Jump to navigation
Jump to search
Formatting tweaks and general overhaul to the "Getting Properties of a Quest Script" subsection. In my opinion it was rather complex and poorly formatted. This edit states the same information in a simple and clean manner.
imported>Evernewjoy |
imported>Delfofthebla (Formatting tweaks and general overhaul to the "Getting Properties of a Quest Script" subsection. In my opinion it was rather complex and poorly formatted. This edit states the same information in a simple and clean manner.) |
||
Line 83: | Line 83: | ||
int property myInt = 5 auto | int property myInt = 5 auto | ||
</source> | </source> | ||
==Auto Read-only Properties== | ==Auto Read-only Properties== | ||
Line 91: | Line 92: | ||
int property myReadOnlyInt = 20 autoReadOnly | int property myReadOnlyInt = 20 autoReadOnly | ||
</source> | </source> | ||
==Conditional Properties== | ==Conditional Properties== | ||
Line 102: | Line 104: | ||
More information on the conditional keyword can be found in the [[Papyrus_Introduction#Writing_Custom_Functions|Papyrus Introduction]] | More information on the conditional keyword can be found in the [[Papyrus_Introduction#Writing_Custom_Functions|Papyrus Introduction]] | ||
=Getting Properties of a | =Getting Properties of a Quest Script= | ||
==From result script owned by the same quest== | ==From result script owned by the same quest== | ||
Often you will need to get a property of a quest script, and use it in a result script somewhere else. This is one of the more tricky things, but once you understand what's happening, it makes sense. First look at the example, then we'll describe what's happening. | Often you will need to get a property of a quest script, and use it in a result script somewhere else. This is one of the more tricky things, but once you understand what's happening, it makes sense. First look at the example, then we'll describe what's happening. | ||
Line 137: | Line 139: | ||
</source> | </source> | ||
==From Within a Magic Effect Script== | |||
If you want to access any of the Functions or Variables within a quest script (or any script for that matter), you must access that 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: | |||
<source lang="papyrus"> | <source lang="papyrus"> | ||
Scriptname | Scriptname myQuestNameScript extends Quest | ||
; | Int Property PublicInt 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 | ||
Function DamageTarget(Actor akTarget) | |||
;This code will damage the akTarget for PublicInt damage | |||
akTarget.DamageAV("Health", PublicInt) | |||
EndFunction | |||
</source> | </source> | ||
Now that we have defined our quest script and created an accessable property, we can control it from the outside. | |||
<source lang="papyrus"> | <source lang="papyrus"> | ||
Scriptname | Scriptname mySpellEffectScript extends activemagiceffect | ||
myQuestNameScript Property myQuestRef auto | |||
Event OnEffectStart(Actor akTarget, Actor akCaster) | |||
myQuestRef.PublicInt = 20 ;Set the Public Int to 20 | |||
; | myQuestRef.DamageTarget(akTarget) | ||
EndEvent | |||
</source> | </source> | ||
=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. | |||
For a list of objects you can use as a type that are already within the game, visit the [[Script Objects]] page. | |||
'' | |||
=Warnings= | =Warnings= |