This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Universal script
#1
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
Reply
#2
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.
Reply
#3
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?
Reply
#4
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)
Reply


Forum Jump: