CallGlobalFunction - Utility

Member of: Utility Script

Calls a global function synchronously and returns whatever that function does.

SyntaxEdit

Var Function CallGlobalFunction(string asScriptName, string asFuncName, Var[] aParams) native global

ParametersEdit

  • asScriptName: The name of the script containing the function
  • asFuncName: The name of the function to call
  • aParams: The list of parameters to pass

Return ValueEdit

Whatever the global function returns.

ExamplesEdit

; Call "bool Function Exists() global" on script "ScriptExtender" and make a choice based on the return value
Var result = Utility.CallGlobalFunction("ScriptExtender", "Exists", new Var[0])
bool exists = result as bool
if (exists)
  Debug.Trace("We have an extender, so do something cool!")
endIf


; Call "Function AddExternalItem(Form akItem) global" on script "CoolModScript"
; Assume we have an armor property "MyCoolArmor" to pass off
Var[] params = new Var[1]
params[0] = MyCoolArmor as FormĀ ; Must cast as form by hand, even though armor is derived from form
Utility.CallGlobalFunction("CoolModScript", "AddExternalItem", params)

NotesEdit

  • If the script name or function name don't exist, the function will error. You may want to check for the existence of the mod you want to talk to before using this.
  • The parameter types must match exactly. You cannot insert a float into the param array if the function expects an int, or a Actor if the function expects an ObjectReference. Normally the compiler would do these casts for you in a normal function call, but it doesn't know what the parameters are, so it is your responsibility to match them up.
  • The compiler cannot check the script name, function name, or parameters for you, so make sure to triple check everything!

See AlsoEdit