Skip to reading
PCA Script Programming

33. Work with GDScript, Lua and BASIC

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page

PCA Script, native GDScript, Lua, BASIC and visual graphs share a script router and gameplay runtime. They do not share one syntax. Use call_script(id, function, arguments, context) at the boundary and pass ordinary data.

A native GDScript helper can supply an operation PCA does not have. Create a GDScript record

math_native using the native Script workspace. A record without an explicit extends line receives the engine’s script base.

Code example
function run()
    return call_script("math_native", "square_root", [81])
end
Code example
func square_root(value: float) -> float:
    return sqrt(value)

The small block above is GDScript, not PCA Script. A call to square_root with 81 returns 9. A native helper can use supported Godot APIs; it must still be written and tested for the platforms you intend to export.

For a Lua record math_lua, use this module. Lua’s ordinary numeric array syntax starts at 1 inside Lua; data crossing the bridge is normalized to PCA/Godot arrays, which are zero-based in PCA.

Code example
local Script = {}
function Script.add_points(base, bonus)
    return base + bonus
end
return Script
Code example
function run()
    return call_script("math_lua", "add_points", [10, 5])
end

Lua action wrappers that return a signal need Lua’s await(...). PCA calls handle their own suspension; do not paste that Lua await syntax into PCA source.

Page 41 of 357Permalink
Go to page