luup reload causes scene error

I use a code from this thread [url=,18679.msg148510.html#msg148510],18679.msg148510.html#msg148510[/url] to create a time window.

local twSecs = 5 -- Number of seconds in time window local tNow = os.time() local tLastOn = tLastOnD99 or 0 tLastOnD99 = tNow return ((tNow - tLastOn) <= twSecs)

I also changed it to

if tLastOnD99 == nil then
tLastOn = 0

I even used the ‘Edit Startup Lua’ for tLastOnD99 = 0

But sometimes after a few luup reloads / restarts the luup engine says there is an error in the scene because of a nil value. With luatest I found out that it’s the tLastOnD99 that causes the scene to fail.
Does anyone know why it doesn’t change to nil value to 0 even though the scene and startup lua script should adjust this?

This could happen if tLastOnD99 happened to be a string which was not a valid number, for example ‘’.

but tLastOnD99 = os.time() so it should be a valid string right.
Also if I use ‘Edit Startup Lua’ every reload of the luup should make sure that tLastOnD99 = 0

But this line

local tLastOn = tLastOnD99 or 0

will make tLastOn whatever tLastOnD99 is, perhaps ‘’, say. Then your later calculation in the return statement will be invalid.

This only happens sometimes when I hit reload luup/ restart the Vera and not always.
Also the logging say ‘error in scene … tried to call a nil value’.

In luatest I just typed in

if tLastOn == nil then 
print("tLastOn is nil")

This way I found out that tLastOn was still nil

Oh, well, that is a rather different diagnostic from the one you mentioned first. Odd, of course, because there is no function call in your code.

Are you sure that this is all you have in Startup Lua?

Sorry I explained it wrong

I have this code in a scene

[code]local tNow = os.time()
local tLastOn = tLastOnD99 or 0

if (tNow - tLastOn) >= twSecs then
do something
tLastOnD57 = tNow

Because I still had the nil value scene error I also added this line

tLastOnD57 = 0 line in de startup lua

This way I though if something goes wrong in the scene loading (if for some reason it missed a part) the startup lua would correct that.