title: Lua Loop with error detection not working correctly
body: <p>I scripted a simple bot program a week or two ago, and have been building on it with new knowledge as I broaden my understanding.</p>
  
  <pre><code>local B = 1 --Boss check 1 = true, 2 = false
  
  repeat
    function bossCheck()
      local rgb1 = getColor(x,y)
      if rgb1 == (rgb) then
        touchDown(x,y)
        usleep(time)
        touchUp(x,y)
      end
  
      local D = 1 --Delay, corrective action when script is out of sync with loading times
      repeat
        if rgb1 ~= (rgb) then
          D = D + 1
          usleep(time)
        end
      until D == 5
    end
    if D == 5 then
      B = B + 1
    end
  until B == 2
  
  if B == 2 then
    alert("No Boss")
  end
  </code></pre>
  
  <p>This actually worked in a loop until I added the correction check delay. If the <code>function bossCheck()</code> failed, then in my mind it should <code>repeat</code>. Am I wrong in assuming this is workable, or have I misplaced some loop statements?</p>
  
  <p>Prior to this new code I implemented with <code>local D = 1 --for delay</code> I would attempt to touch at my IOS screen twice, it would return <code>not true</code> results and then my loop would end. But as of now, I run my script and nothing happens and it would appear that the script runs indefinately. </p>
  
  <p>It's very confusing. I don't expect a verbatim line I should include here, but kind of hint me into the right direction.</p>
  
  <p>Edit - Example</p>
  
  <p>'function bossCheck ()
     if (getColor(x,y) == "color1") then
        return true;
     end
     return false;
  end</p>
  
  <p>function onBoss ()
     touch(x,y)
     usleep(time)
     return true;
  end</p>
  
  <p>function fightBoss ()
     touch(x2,y2)
     usleep(time)
     return true;
  end</p>
  
  <p>function bossReturn ()
     touch (x3,y3)
     usleep(time)
     return true;
  end</p>
  
  <p>function bossLoop ()
     while (bossCheck) do
        onBoss ();
        fightBoss ();
        bossReturn ();
     end
  end</p>
  
  <p>repeat
     bossLoop ();
  until (bossCheck == false)</p>
  
  <p>if (bossCheck == false) then
     alert("Boss Loop End")
  end</p>
  
  <p>'</p>