Posts: 7
	Threads: 4
	Joined: May 2020
	
Reputation: 
0
	 
	
	
		Hi everyone. I am a new LM and lua user, I wonder how can I realize the time loop control? e.g. when I trigger 1/1/1=1, then 1/1/2=1, 1s,1/1/3=1, 1s, 1/1/4=1, and return. When I trigger 1/1/1=0, stop the loop. Thanks a lot
	
	
	
	
		
	
 
 
	
	
	
		
	Posts: 5284
	Threads: 29
	Joined: Aug 2017
	
Reputation: 
237
	 
	
	
		I would do it by two scripts. First event attached to your 1/1/1 which will enable/disable the second resident script. 
Code:
value = event.getvalue()
if value then
 script.enable('loop')
else
script.disable('loop')
end
Second is resident script with interval of 1s and such code. 
Code:
grp.write('1/1/2', true)
os.sleep(1)
grp.write('1/1/3', true)
os.sleep(1)
grp.write('1/1/4', true)
In this example I called resident script 'loop' if you use different name change it in the first script
	
------------------------------
Ctrl+F5
	
		
	
 
 
	
	
	
		
	Posts: 5284
	Threads: 29
	Joined: Aug 2017
	
Reputation: 
237
	 
	
	
		Yes but running while loop in event based script for a longer time it is not the best idea.  This is the most efficient way for processes.  Otherwise you have to make sure that you won't run the same script more than once before ending the previous script.
	
	
	
------------------------------
Ctrl+F5