CastAs - ScriptObject
From Creation Kit
Member of: ScriptObject Script
Attempts to cast this script as a different script, but without adding a dependency on the calling script.
ScriptObject Function CastAs(string asScriptName) native
- asScriptName: The script to cast to
The casted script, if possible, otherwise None.
; Call "Function MakeACake()" on script "Latrop" ; We use CastAs to make sure we don't depend on the script we want to call the function on ScriptObject latropScript = FormFromOtherMod.CastAs("Latrop") if latropScript ; make sure the cast succeeded latropScript.CallFunction("MakeACake", new Var) endIf
- If the script doesn't exist, or isn't attached to the form in question the function will simply return None, just like a cast operation.
- Unlike a cast operation, you do not have to cast "down" the inheritance tree first. For example, it will let you cast from "ScriptA" directly to "ScriptB" if they are attached to the same form, even if you would normally have to go through "ObjectReference".
- If two copies of the same script are attached to the same form, it is undefined which one you will get. For example, if both "ScriptA" and "ScriptB" are attached to a reference, both inheriting from "ObjectReference" and you pass "ObjectReference" as the parameter to CastAs, which script you actually get is effectively random.
- The compiler cannot check the script name for you, so make sure to triple check everything!