50. Include a PCA script library
func add_points(base: int, bonus: int = 1) -> int:
return base + bonusfunc run() -> int:
return add_points(10, 5)Put the example in a separate native record utility_gd. An IncludeScript call returns a script-call proxy, not pasted source and not the other record’s actual Node instance.
func run() -> int:
var library: Variant = IncludeScript("utility_gd")
var total: Variant = await library.Call("add_points", [10, 5])
library.Set("last_total", total)
return int(library.Get("last_total", 0))Call invokes a named function; Run invokes run. Get/Set use the included-variable store, separate from the library’s member variables. A one-argument IncludeScript does not execute the library function by itself.
Global.Get(id) provides the same sort of call proxy. Use the public wrapper to inherit caller context, and use unique script IDs. Global is not a native Godot autoload singleton you can assume exists in an unrelated .gd file.
