TEMPEST.114 Posted January 20, 2023 Share Posted January 20, 2023 (edited) I've been working on my own 'superscript' and at 17000 lines long (with lots of comments) it's too unwieldy and for debugging I want to be able to remove sections in case of 'contamination'. I'm still learning Lua and it's intricacies but what I came up with was my main script would be called by the mission at MISSION START and then any 'modules' I wanted to run would be specified by 'require' at the top. Here's what I have in cut down form: package.path = package.path .. ';C:\\TEMPESTsLuaControls\\Modules\\?.lua' local TLO = require "TLO" -- local TPH = require "TPH" -- local TMB = require "TMB" TLC = { ["Version"] = "2.0.0" } world.addEventHandler(TLC) TLO.LogWrite("TLC", "INFO", "Initialisation Complete. Version %s", self.Version) The first 'module' - my logging / output module, also is supposed to exist in the Lua 'mission' environment, just like the main script, but log.write no longer works. Even worse env.info doesn't work either. I get the 'log' or 'env' is nil error. Here's how my 'modules' are defined: module("TLO") TLO = { ["Version"] = "2.0.0" } function TLO.LogWrite(source, level, message, ...) log.write(source, log[level:upper()], string.format(message, ...)) end function TLO.InitialiseTLO() TLO.LogWrite("TLO", "INFO", "Initialisation Complete. Version %s", TLO.Version) end TLO.InitialiseTLO() I know I'm missing or haven't understood some core part of Lua but I've spent two days on this and even got a copy of 'Programming in Lua 2nd Edition' on the way from Amazon, but I'm lost at where I've gone wrong. Edited January 20, 2023 by Elphaba Link to comment Share on other sites More sharing options...
TEMPEST.114 Posted January 20, 2023 Author Share Posted January 20, 2023 So the answer isn't to use modules, because each module creates it's own 'Lua Environment State' i.e. it won't be in 'mission' anymore so can't use anything from DCS. Instead I'm using loadfile and it's working fine. Link to comment Share on other sites More sharing options...
Recommended Posts