Logic Machine Forum
Start multiple scripts - 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: Start multiple scripts (/showthread.php?tid=4356)



Start multiple scripts - Novodk - 07.11.2022

Hi, I need some guidance, I have 10 Event-based/Resident scripts that I need to be able to start from one button and stop from another button.

The scripts i have is as follows:

Event-based:

solenoid_address = '2/0/20'

value = event.getvalue()
script.set('solenoid_east', value)
grp.checkwrite(solenoid_address, value)

Resident:

solenoid_address = '2/0/20'
grp.checkwrite(solenoid_address, true)
os.sleep(60)
grp.checkwrite(solenoid_address, false)
os.sleep(300)

I have 10 similar scripts for different solenoids

If they press "start all" all the scripts should turn on, if one of the scripts was already started it just keeps running

If they press "stop all" all the scripts should stop no matter what.

And can i use the "start button" to indicate only if all solenoids is on?
And the "stop button" to indicate only if all solenoids is off.

Ohh and is it possible to add a delay so that I don't start all the scripts at the same time? (water pressure)


I don't know if my approach with individually scripts is the right way of doing it?

If not can you turn me in the right direction?


RE: Start multiple scripts - admin - 07.11.2022

Multiple scripts can be controlled together using categories: https://openrb.com/docs/lua.htm#script.categoryset
But I suggest using a single resident script to control all solenoids to guarantee that there's a delay between turning different solenoids on and off.


RE: Start multiple scripts - Novodk - 08.11.2022

Thank you for pointing me in the right direction.
I got it working but I would like my button(virtual object 62/1/5 01.001 switch) to go back to off when it have executed the script, is that possible?
Tried to just grp.write('62/1/5', false) in the end of my script, but then it just runs the script again.


RE: Start multiple scripts - admin - 09.11.2022

See this example on how to prevent script being executed when triggered by an event script: https://forum.logicmachine.net/showthread.php?tid=3821&pid=24808#pid24808