I have some functions and variables that are currently in an “initialization” scene that I want code in other scenes to be able to use - but the “initialization” scene needs to run first to globalize the functions and variables before the other scene functions can “see” it.
How do I get that initialization code to run whenever the lua engine starts up?
Either I need a way to make the current scene run automatically on startup or I place the code somewhere else?
Neillos,
I was going to recommend that you try editing the Startup Lua under Luup Plugins --> Edit Startup Lua, but then I tried a snippet of code myself in 1.0.862:
and checked the logs after Save and also after rebooting Vera to get the whole startup sequence. In both cases, there was no output in [tt]/var/log/cmh/LuaUPnP.log[/tt] so either:
a) Startup Lua codeblocks never fire OR;
b) [tt]luup.log(…)[/tt] doesn’t work during startup blocks
at any rate, once it can be verified, this seems like the logical “trigger” spot to put the type of code you’re writing.
There are other options, like Lua modules, but they’re increasing the level of complexity for what you’re doing. I’d like to see the simple ones work first.
MCV: Does the Startup Lua block work under Luup Plugins --> Edit Startup Lua?
I have found that some things do not work when run in the LUA startup code, most likely because the startup code is executed before the environment has been fully brought up.
I solved this by creating a scene (I called “Initialize”), that gets called as the last thing the start up code does. The Initialize scene will not actually run until the environment is ready to go, so things that require that environment can safely run from within that scene.
I did this because I wanted to lock my doors when Vera restarts, but the locking would not work when executed in the Startup code.