Difference between revisions of "Cast Reference"

945 bytes added ,  08:46, 28 March 2012
no edit summary
imported>Jlundin
 
imported>Kahmul
Line 130: Line 130:


Nothing can be cast to an array, even other arrays if the base types would normally cast just fine.
Nothing can be cast to an array, even other arrays if the base types would normally cast just fine.
== Cast to different types ==
Casting types to different ones might be useful i.e. if you want to know the type of the object triggered with your triggerzone. But, for example, you can't cast an ObjectReference to a Weapon or compare them. In this case you can work with the "Form"-Type.
=== Examples ===
<source lang="papyrus">
Weapon Property MyUberWeapon auto
OnTriggerEnter(ObjectReference Type)
Weapon triggeredWeapon = (type as form) as weapon  ; Cast the triggered object first to a form and then to a weapon.
if(triggeredWeapon == MyUberWeapon)
  ; if triggeredWeapon is equal to MyUberWeapon, do something.
endif
EndEvent
</source>
But if you only want to determine the type of the object, you could also use a keyword:
<source lang="papyrus">
Keyword Property IsAnArrow auto
OnTriggerEnter(ObjectReference Type)
if(type.haskeyword(IsAnArrow))
  ;if the object type has our keyword, do something.
endif
EndEvent
</source>


[[Category:Scripting]]
[[Category:Scripting]]
[[Category:Papyrus]]
[[Category:Papyrus]]
[[Category:Papyrus Language Reference]]
[[Category:Papyrus Language Reference]]
Anonymous user