Logic Machine Forum
How to stop this script when running - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: How to stop this script when running (/showthread.php?tid=5358)



How to stop this script when running - TimmiA - 12.04.2024

Hi Everyone.

Question one:
This is a scheduled script (script name: Ligths_UP), is there at way to enable/disable it by the use of a grp.adress?

e.g:
if start == true then 
script.enable(Ligths_UP)
else
script.disable(Ligths_UP)


Question Two:
When this script is started i can't stop i from running again. 
It will only stop when value_end is reached.
Is there a way to stop it halfway?

value_sek = grp.getvalue('32/1/4')
value_end = grp.getvalue('32/1/3')
start = grp.getvalue('32/1/1')


-- UP
output = '32/1/2'
for i = grp.getvalue(output) + 1, value_end, 1 do
  grp.write(output, i)
  os.sleep(value_sek)
end

Best regards
Timmi Andersen
Denmark


RE: How to stop this script when running - admin - 12.04.2024

1. Script name in enable/disable must be in quotes. Right now you are referring to a variable named Ligths_UP that's not defined. Alternatively you can simply use grp.getvalue() in
your script to determine whether it should run or not:
Code:
-- run only if 1/1/1 value is true
if grp.getvalue('1/1/1') then
  -- do something
end

2. You can set the event script "Execution mode" to "Last instance only" and only execute your action when the event value is true. Sending false will stop the previous script instance.
Code:
if event.getvalue() then
  -- do something
end