Logic Machine Forum
Universal script - 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: Universal script (/showthread.php?tid=4281)



Universal script - Borek - 03.10.2022

Hi, I'm not very knowledgeable about Lua programming. I have several of the same scripts that are different in group addresses. The latter shifts by 1, for example 1/3/10, 1/3/11 etc. Is it possible to write one universal script that would adjust the other addresses in it according to the incoming address and execute?

thanks

example:
roofopenclose = grp.getvalue('2/3/10') --address coming from basalte
roofopen = grp.getvalue ('2/3/200') --address for the actuator
roofclose = grp.getvalue ('2/3/201') -- address for the actuator

if roofopenclose == false then
  grp.write('2/3/200',1) --command OPEN for ROOF 1 actuator
  os.sleep(1) --long push
  grp.write('2/3/200',0) --command for actuator
elseif roofopenclose == true then
  grp.write('2/3/201',1) --command CLOSE for ROOF 1 actuator
  os.sleep(1) --long push
  grp.write('2/3/201',0) --command for actuator
end


RE: Universal script - admin - 04.10.2022

Add to Common functions:
Code:
function longpress(event, shift)
  local dst = event.dstraw + shift

  if event.getvalue() then
    dst = dst + 1
  end

  grp.write(dst, true)
  os.sleep(1)
  grp.write(dst, false)  
end

Add event script to 2/3/10:
Code:
longpress(event, 190)

If you have a fixed address shift of 190 (2/3/10 -> 2/3/200 and 2/3/201) then you can add a common tag to all source objects (2/3/10, 2/3/11, 2/3/12 etc) and map a single event script to this tag.


RE: Universal script - Borek - 04.10.2022

Thank you admin, but I didn't express myself accurately. Group address 2/3/10 triggers the event script with addresses 2/3/200 and 2/3/201. Group address 2/3/11 runs an event script with addresses 2/3/202 and 2/3/203, address 2/3/12 runs an event script with addresses 2/3/204 and 2/3/205 ...etc. Is it possible to have one script?


RE: Universal script - admin - 05.10.2022

The calculation was wrong in the previous example.
Add a common tag to input objects (2/3/10, 2/3/11, 2/3/12 etc) and map an event script to this tag (no need to add anything to Common functions).
Code:
basein = buslib.encodega('2/3/10')
baseout = buslib.encodega('2/3/200')
dst = baseout + 2 * (event.dstraw - basein)

if event.getvalue() then
  dst = dst + 1
end

grp.write(dst, true)
os.sleep(1)
grp.write(dst, false)