How can I add lua modules in engine scripts?
Posted: Wed Aug 22, 2018 9:54 am
Hi there, in the interest of keeping things organised, I've been wanting to create libraries of more common functions that I use. Suppose for instance I have a speedometer that I want to give some fancyness. I have two .lua files, one being the engine script (we shall name in EngineScript.lua), the other being the library of functions for the speedometer (call it flaman.lua). Both files reside in the same folder in my main engine folder. I've used this tutorial for reference purposes.
The contents of flaman.lua are:
The (relevant) contents of EngineScript.lua are:
However, this blows up. In fact, I am confident that it blows up at the line where the module is loaded. The daft thing is that I don't really see what I'm doing wrong here!
The contents of flaman.lua are:
- Code: Select all
local flaman = {}
-- this is just to try things out.
function flaman.update(speed)
return 3.6*speed
end
return flaman
The (relevant) contents of EngineScript.lua are:
- Code: Select all
-- Load modules
flaman = require("flaman")
... So here's where initialise() and setup() happen but I can't be bothered to write pseudocode for that ...
-- Then do stuff in update()
function update(dTime)
-- Query TS about how fast we're going.
local speed = Call("GetSpeed")
-- Let's do something with the speedometer!
local TheSpeedToDisplay = flaman.update(speed)
end
However, this blows up. In fact, I am confident that it blows up at the line where the module is loaded. The daft thing is that I don't really see what I'm doing wrong here!