Hi.
I'd previously posted here about trying to run a Lua script that would pass variables onto the script that started it. For example...
local _, returnedVariables = shell.run("mod")
I understand that returning variables is not a functionality of shell.run; I was merely using it as an example. Bomb Bloke had suggested that I use textutils.unserialize to manually read the mod file and convert it into a table, and if necessary, load it as an API to execute code. However, this really doesn't work. I've looked into it and textutils.unserialize does not support functions within the table, and os.loadAPI doesn't allow any kind of return values either.
In regards to my previous post, I believe I should have been a bit more specific and detailed:
Mod file:
--init code up here
mod = {
name = "testMod",
--more arbitrary properties here
mouse_click = function()
print("test!")
end,
timer = function(event)
if event[2] == "timer" then
print("another test!")
end
end
}
return mod
Basically, the modding is event based. Any event that has a function attached to it will execute in the game code once that event is triggered. My only problem here is that nothing I've tried can return variables to the script that started it like a function. I've considered using environments somehow and came up with the idea of putting it in _G for the game to retrieve. Although I'm sure there's a better way to do it - any suggestions?