Run only one scene at the same time

I have several scenes which execute lua code. It is important that they are not running at the same time but in serial order.

For this I use a variable “in_use” and a retry function which tries again for a limited amount of times.

It works perfectly in terms that it doesn’t run if another one is running but the retry function doesn’t work. Can someone please give me a hint why?

Thanks

function check() local in_use = luup.variable_get("urn:upnp-org:serviceId:VContainer1","Variable3",241) if in_use == "0" then luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable3","1",241) do_something() else if retries > 0 then retries = retries-1 luup.call_delay( 'check', 10 ) else return false end end end local retries = 5 check()

You have defined retries as a local variable but check() is global (and must be). When check() executes, retries no longer exists so returns nil. One fix is to pass the retry count as a string parameter:

function check(retstr) local in_use = luup.variable_get("urn:upnp-org:serviceId:VContainer1","Variable3",241) if in_use == "0" then luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable3","1",241) do_something() else local retries = tonumber(retstr) if retries > 0 then retries = retries-1 luup.call_delay( 'check', 10,retries ) else return false end end end check("5")

That works perfectly - thank you!