Require() in Lua with commandArray
Posted: Friday 26 August 2016 14:48
Hi,
I've read a few posts on how to do a require() in lua and I think I have the basics. I'm unclear however how to handle it if the function I would like to load adds to my command array. By way of example I have the following two functions in my motion scripts. Once called set next, and one called scene_on_off (the substance of these can largely be ignored, the issue is that they both add to the command array). How could I move scene_on_off into a different lua file?
Is it as simple as having the sub function not return anything but instead generate its own commandArray?
Thanks
I've read a few posts on how to do a require() in lua and I think I have the basics. I'm unclear however how to handle it if the function I would like to load adds to my command array. By way of example I have the following two functions in my motion scripts. Once called set next, and one called scene_on_off (the substance of these can largely be ignored, the issue is that they both add to the command array). How could I move scene_on_off into a different lua file?
Code: Select all
function set_next(room_name,active_scene, room_countdown,countdown)
if otherdevices['$' .. room_name .. " Active"] == 'Off' then
--turn on the light
scene_on_off(room_name, active_scene, 'On')
-- set the scene name
scene_name = "Scene:" .. room_name .. " Lights " .. active_scene
print('script_device_MotionTriggered: ' .. room_name .. '- activing ' .. scene_name)
--reset the countdown
if ( uservariables[room_countdown] > countdown) then
commandArray['Variable:'.. room_countdown]= tostring(countdown)
end
else
print('script_device_MotionTriggered: ' .. room_name .. ' - ' .. active_scene .. ' already active')
end
end
Code: Select all
function scene_on_off (room_name, active_scene, on_off)
commandArray["Scene:" .. room_name .. " Lights " .. active_scene]= on_off
end
Thanks