Talk:Script File Structure

From the Fallout4 CreationKit Wiki
Jump to navigation Jump to search

Imports with global function via inheritance[edit source]

I may have found a quirk when importing global functions from another script. If the global functions you're importing are from a parent via inheritance, the compiler cannot resolve the global function.

Papyrus

Scriptname MyNamespace:ObjectBase

Function MyGlobalFunction() Global
	{Global Function}
EndFunction


Scriptname MyNamespace:Object extends MyNamespace:ObjectBase
import MyNamespace:ObjectBase

Event OnInit()
        MyGlobalFunction() ; compiler error below
EndEvent
global function MyGlobalFunction cannot be called on an object
Error while trying to typecheck script MyNamespace:Object: Index (zero based) must be greater than or equal to zero and less than the size of theNo output generated for MyNamespace\Object.psc, compilation failed.

The error above goes away and can be imported if the globals are relocated to a script outside the `Objects` inheritance.

Scriptname MyNamespace:Other

Function MyGlobalFunction() Global
	{Global Function}
EndFunction


Scriptname MyNamespace:Object extends MyNamespace:ObjectBase
import MyNamespace:Other

Event OnInit()
        MyGlobalFunction()
EndEvent

Scrivener07 (talk) 2017-08-06T16:13:12 (EDT)

Fragments[edit source]

It appears you can't import functions into a fragment. :/ --Rasikko (talk) 2018-10-28T01:56:55 (EDT)

But you can still import them using the standard syntax (ScriptName.Scriptfunction) --Rasikko (talk) 2018-10-28T03:13:29 (EDT)
Are you sure about that? A fragment is still a normal script file even though the CK does some code generation to hide the "scary" parts from people without a programming background. View and edit the fragments source and you will see that you can add an import. Let me know if you have further questions. Fragments are a bit odd. Scrivener07 (talk) 2018-10-28T12:23:55 (EDT)
I haven't tried the edit fragment part. I just tried putting it in the fragment field. I'll clarify that this was attempted with a terminal fragment. --Rasikko (talk) 2018-10-29T00:50:58 (EDT)