Difference between revisions of "BuildRef"
Jump to navigation
Jump to search
added info to avoid a CTD
imported>Odessa (more concise) |
imported>Odessa (added info to avoid a CTD) |
||
|
if IsModLoaded "SomePopularCompanionMod.esp"
set iModIndex to GetModIndex "SomePopularCompanionMod.esp"
set rRainySmiles to BuildRef iModIndex, 1068677
endif
</pre>
==
You can avoid CTDs by ensuring the return is both a valid form, and of the type you expect it to be, using [[IsFormValid]], and functions like [[IsReference]], [[IsActor]] or [[GetType]]. For example, following on from the code above, where we want to get a companion added by an external mod:
<pre>
if eval !(IsFormValid rRainySmiles)
; The Form is NOT valid, do not proceed!
return
elseif eval !(IsReference rRainySmiles)
; The form is NOT a reference, its something else, do not proceed!
return
elseif eval !(rRainySmiles.IsActor)
; The form is a reference, but NOT an actor (maybe its a door or something)!
return
else
; Its all good, we got an actor from the buildref so we can proceed
endif
; "if eval !(condition)" just means "if conditon is false"
</pre>
Or you can use [[GetType]] for any types:
<pre>
if eval !(IsFormValid SomeBuildRefSpell)
; The Form is NOT valid, do not proceed!
return
elseif GetType SomeBuildRefSpell != 20 ; * 20 is the code for 'spell'
; I was expecting a spell but got something else, do not proceed!
return
else
; Its safe, I got a spell like I expected
PlayerREF.CIOS SomeBuildRefSpell
endif
</pre>
Note: You must use multiple lines for the <b>if</b> statements, not <b>&&</b>, because the GECK always evaluates all conditons on a line.
==See Also==
*[[IsModLoaded]]
*[[GetModIndex]]
*[[GetLocalRefIndex]]
*[[IsFormValid]], [[IsReference]], [[IsActor]], [[GetType]]
*[[Eval]]
[[Category:Functions_(NVSE)]]
| |||