Difference between revisions of "GetSelf"

442 bytes added ,  08:47, 13 January 2017
no edit summary
imported>Cipscis
(Updated to use Function template; fixed bad example; added note about implicit reference syntax)
imported>Tgspy
 
(3 intermediate revisions by 2 users not shown)
Line 4: Line 4:
  |summary = Returns the RefID of the calling reference.  [[GetSelf]] is only useful when this information is accessed externally, or when the scripted reference's RefID needs to be passed as a parameter to a function like [[PushActorAway]]
  |summary = Returns the RefID of the calling reference.  [[GetSelf]] is only useful when this information is accessed externally, or when the scripted reference's RefID needs to be passed as a parameter to a function like [[PushActorAway]]
  |alias = this
  |alias = this
|referenceType = Reference
  |example = ref rSelf
  |example = ref rSelf
  set rSelf to GetSelf
  set rSelf to GetSelf
Line 12: Line 11:
==Notes==
==Notes==
<ul>
<ul>
<li>Because reference functions can be called on the scripted reference implicitly by omitting explicit reference syntax, the following code structure should never be used:
<li>While functions that take an implied reference can be cast without needing a variable or call to getself, like so:
<pre>ref rSelf
<pre>CIOS someSpell</pre>
Doing so may not be clear, and makes the code less portable if moved to a different script that does not support the implied reference.  For this reason, modders should prefer the more expressive syntax:
<pre>
ref rSelf
set rSelf to GetSelf
set rSelf to GetSelf
rSelf.ReferenceFunction</pre>
rSelf.CIOS someSpell</pre>
Instead, just use code like this:
Not only for CIOS, but for all "reference methods" that require a reference, like CIOS.
<pre>ReferenceFunction</pre>
</li>
<li>[[GetSelf]] will return 0 if called on a reference that has been created dynamically (for example, created via [[PlaceAtMe]], or dropped from an inventory into the game world).
</li>
</li>
</ul>
</ul>
*Using GetSelf in scripts rather than  this will result in GECKPU throwing errors.


[[Category:Functions]]
[[Category:Functions]]
Anonymous user