Lua Scripting¶
Lua is the scripting language for all game logic in SplashEdit. Scripts control object behavior, UI, audio, scene transitions, and more.
Important: This is NOT Standard Lua¶
The Lua VM running on PS1 uses fixed-point numbers instead of floating-point. The PS1 has no floating-point hardware. This changes how you write math:
- There are no decimal numbers.
0.5does not exist. - Integer division gives integers.
1/2equals0, not0.5. - Use
FixedPoint.new()for ALL fractional values. This is the only way to get non-integer numbers.
Read Fixed-Point Math before writing any scripts. This is the single most important thing to understand.
Script Types¶
There are three types of Lua scripts:
Scene Scripts¶
Attached to the Scene Exporter. Run during scene initialization. This is where you define shared functions, set up UI, and initialize game state.
Object Scripts¶
Attached to individual PSXObjectExporter components. Define per-object behavior through event callbacks like onInteract, onCollideWithPlayer, and onButtonPress.
Trigger Scripts¶
Attached to PSXTriggerBox components. Handle onTriggerEnter and onTriggerExit events.
Creating Lua Scripts¶
- Create a
.luafile in your Unity project's Assets folder - Unity imports it automatically as a
LuaFileScriptableObject - Assign the LuaFile to a Scene Exporter, Object Exporter, or Trigger Box
Script Environments¶
Each script runs in its own environment. Functions defined in one script are NOT automatically available to other scripts. To share functions (for example, from a scene script to object scripts), publish them to _G:
-- In scene.lua
function addScore(amount)
-- ...
end
-- Publish so object scripts can call it
_G.addScore = addScore
Then any object script can call addScore(100) directly, because _G is the fallback for all environments.
What's in This Section¶
- Fixed-Point Math - How numbers work on PS1 (read this first!)
- Event Callbacks - All available callbacks and when they fire
- API Reference - Complete reference for every Lua function
- Patterns & Best Practices - Working code patterns for common game mechanics