Logic Machine Forum
Go-to statement - 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: Go-to statement (/showthread.php?tid=3567)



Go-to statement - fabiorusco - 20.09.2021

(08.05.2021, 19:29)fabiorusco Wrote: Hello,
I need use the goto statement for avoid to execute some commands.
How I can implement it?
Fabio

I have created some script for turn on and off the light of a garden, some of this are inserted in more comand (see the picture).
When I turn on there are no problems, When I turn off i need to control if one of the lamps are on by another command. This situation it's too much slow and the costumer want avoid this. Can you help me please.
Best regards



Script:
Code:
for i, object in ipairs(grp.tag('ccGPAL')) do
  if not object.data then
-- Accendo LED accendo tutte le luci
    grp.write('0/1/110', true)
    os.sleep(0.2)
    grp.write('6/0/30',true)
    os.sleep(0.2)
    grp.write('6/0/31',true)
    os.sleep(0.2)
    grp.write('6/0/32',true)
    os.sleep(0.2)
    grp.write('6/0/33',true)
    os.sleep(0.2)
    grp.write('6/0/34',true)
    os.sleep(0.2)
    grp.write('6/0/35',true)
    os.sleep(0.2)
    grp.write('6/0/46',true)
    os.sleep(0.2)
    grp.write('6/0/47',true)
    os.sleep(0.2)
    grp.write('6/0/58',true)
    os.sleep(0.2)
    grp.write('6/0/59',true)
    os.sleep(0.2)
    grp.write('6/0/60',true)
    os.sleep(0.2)
    grp.write('6/0/61',true)
    os.sleep(0.2)
--Flash LED
    grp.write('0/1/110', false)
    os.sleep(0.4)
    grp.write('0/1/110', true)
    return
  end
end
-- Spengo il LED
grp.write('0/1/110', false)
-- controllo 1° gruppo
G1=0
for i, object in ipairs(grp.tag('ccGEA')) do
  if not object.data then
goto passo11
  end
end
G1=1
::passo11::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGEP')) do
  if not object.data then
goto passo12
  end
end
G1=1
::passo12::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGIP')) do
  if not object.data then
goto passo13
  end
end
G1=1
::passo13::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPPC')) do
  if not object.data then
goto passo14
  end
end
G1=1
::passo14::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPPG')) do
  if not object.data then
goto passo15
  end
end
G1=1
::passo15::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPPL')) do
  if not object.data then
goto passo16
  end
end
G1=1
::passo16::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPPO')) do
  if not object.data then
goto passo17
  end
end
G1=1
::passo17::
if G1==0 then
  grp.write('6/0/30',false)
  os.sleep(0.2)
  grp.write('6/0/31',false)
end
-- controllo 2° gruppo
G2=0
for i, object in ipairs(grp.tag('ccGEA')) do
  if not object.data then
goto passo21
  end
end
G2=1
::passo21::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGEB')) do
  if not object.data then
goto passo22
  end
end
G2=1
::passo22::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGEP')) do
  if not object.data then
goto passo23
  end
end
G2=1
::passo23::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPBC')) do
  if not object.data then
goto passo24
  end
end
G2=1
::passo24::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPBL')) do
  if not object.data then
goto passo25
  end
end
G2=1
::passo25::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPBO')) do
  if not object.data then
goto passo26
  end
end
G2=1
::passo26::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPPG')) do
  if not object.data then
goto passo27
  end
end
G2=1
::passo27::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPPL')) do
  if not object.data then
goto passo28
  end
end
G2=1
::passo28::
if G2==0 then
  grp.write('6/0/32',false)
  os.sleep(0.2)
  grp.write('6/0/33',false)
end
-- controllo 3° gruppo
G3=0
for i, object in ipairs(grp.tag('ccGEA')) do
  if not object.data then
goto passo31
  end
end
G3=1
::passo31::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGEB')) do
  if not object.data then
goto passo32
  end
end
G3=1
::passo32::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGEP')) do
  if not object.data then
goto passo33
  end
end
G3=1
::passo33::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPBL')) do
  if not object.data then
goto passo34
  end
end
G3=1
::passo34::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPPG')) do
  if not object.data then
goto passo35
  end
end
G3=1
::passo35::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPPO')) do
  if not object.data then
goto passo36
  end
end
G3=1
::passo36::
if G3==0 then
  grp.write('6/0/34',false)
  os.sleep(0.2)
  grp.write('6/0/35',false)
end
-- controllo 4° gruppo
G4=0
for i, object in ipairs(grp.tag('ccGEA')) do
  if not object.data then
goto passo41
  end
end
G4=1
::passo41::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGEP')) do
  if not object.data then
goto passo42
  end
end
G4=1
::passo42::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPAC')) do
  if not object.data then
goto passo43
  end
end
G4=1
::passo43::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPAO')) do
  if not object.data then
goto passo44
  end
end
G4=1
::passo44::
os.sleep(0.1)
if G4==0 then
  grp.write('6/0/46',false)
  os.sleep(0.2)
  grp.write('6/0/47',false)
end
-- controllo 5° gruppo
G5=0
for i, object in ipairs(grp.tag('ccGPBL')) do
  if not object.data then
goto passo51
  end
end
G5=1
::passo51::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPEL')) do
  if not object.data then
goto passo52
  end
end
G5=1
::passo52::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPPL')) do
  if not object.data then
goto passo53
  end
end
G5=1
::passo53::
os.sleep(0.1)
if G5==0 then
  grp.write('6/0/58',false)
  os.sleep(0.2)
  grp.write('6/0/59',false)
end
-- controllo 6° gruppo
G6=0
for i, object in ipairs(grp.tag('ccGP')) do
  if not object.data then
goto passo61
  end
end
G6=1
::passo61::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPBL')) do
  if not object.data then
goto passo62
  end
end
G6=1
::passo62::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPEC')) do
  if not object.data then
goto passo63
  end
end
G6=1
::passo63::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPEG')) do
  if not object.data then
goto passo64
  end
end
G6=1
::passo64::
os.sleep(0.1)
for i, object in ipairs(grp.tag('ccGPPL')) do
  if not object.data then
goto passo65
  end
end
G6=1
::passo65::
if G6==0 then
  grp.write('6/0/60',false)
  os.sleep(0.2)
  grp.write('6/0/61',false)
end
--Flash LED
grp.write('0/1/110', true)
os.sleep(0.4)
grp.write('0/1/110', false)



RE: Go-to statement - admin - 20.09.2021

You don't need to use goto here. You should replace it with tag_or function if you want to check if a least one of tagged objects is ON. See this: https://forum.logicmachine.net/showthread.php?tid=220&pid=961#pid961

It's hard to understand from the code what exactly this script is doing. Can you explain the task in more detail?