0

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.

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

This actually worked in a loop until I added the correction check delay. If the function bossCheck() failed, then in my mind it should repeat. Am I wrong in assuming this is workable, or have I misplaced some loop statements?

Prior to this new code I implemented with local D = 1 --for delay I would attempt to touch at my IOS screen twice, it would return not true 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.

It's very confusing. I don't expect a verbatim line I should include here, but kind of hint me into the right direction.

Edit - Example

'function bossCheck () if (getColor(x,y) == "color1") then return true; end return false; end

function onBoss () touch(x,y) usleep(time) return true; end

function fightBoss () touch(x2,y2) usleep(time) return true; end

function bossReturn () touch (x3,y3) usleep(time) return true; end

function bossLoop () while (bossCheck) do onBoss (); fightBoss (); bossReturn (); end end

repeat bossLoop (); until (bossCheck == false)

if (bossCheck == false) then alert("Boss Loop End") end

'

4
  • 1
    From the code you posted, you defined a function bossCheck, but it's never called. Commented Feb 5, 2015 at 2:40
  • What is rgb? What is rgb1 outside of the bossCheck function? Commented Feb 5, 2015 at 2:43
  • I still have a bit to learn about functions it would seem. From what I read, functions can be set locally in blocks, yes. Commented Feb 5, 2015 at 7:10
  • Rgb1 is just a string to call function getColor it helped with labeling them differently when I had 5 or so colorChecks. Commented Feb 5, 2015 at 7:11

1 Answer 1

0

Ok, repeat until executes the given script over and over until it reaches a statement.

Your script, re-define bossCheck as a function and checks if D equal to 5 (D is nil).

You do not call anywhere bossCheck, and because of that B remains 1.

This script should work.

local noBoss = false;
function bossCheck()
    noBoss = false;
    local rgb1 = getColor(x,y);
    if (rgb1 == rgb) then
      touchDown(x,y)
      usleep(time)
      touchUp(x,y)
      return -- if it's true, stop the function here;
    end
    noBoss = true;
    usleep(time * 5); -- no point delaying application action 5 times, when we call just multiply the sleep amount by 5;
end

repeat
    bossCheck();
until noBoss;

if (noBoss) then
    alert("No Boss");
end

Edit:

An example how I'd call several functions in sequence

function bossCheck()
    if (getColor(x,y) == rgb) -- instead doing rgb1= ..
        touchDown(x,y)
        usleep(time)
        touchUp(x,y)
        return true;
    end
    return false;
end
while true do
    if (not bossCheck()) then
        alert("No Boss");
        break; -- break out of the loop
    end
    if ((function () return true)()) then
        alert("This local function return true.. so alert message is shown\nYou can do the same with any other functions");
    end
end

According to your example you can just do this

function bossCheck()
    if (getColor(x,y) == rgb) -- instead doing rgb1= ..
        return true;
    end
    return false;
end

while true do
    if (bossCheck()) then
        touch(x,y)
        usleep(time)
        touch(x2,y2)
        usleep(time)
        touch(x3,y3)
        usleep(time)
    else
        alert("No Boss");
        break; -- break out of the loop
    end
end
Sign up to request clarification or add additional context in comments.

8 Comments

So you can set any logic block to function? And when you call until noBoss this means to check if the statement had been changed to =true.
So this script worked, if (noBoss) then alerted me. Can I add else if the check returns false and there actually is a boss.
You can add else and print if there is an boss, though it will never be printed, because once you break the loop it means noBoss is true, so it'll alert 'no boss', to print that there is a boss, just add alert in the bossCheck function.
If the function returns true, it will alert. But if it is false and if it returns false it will keep looping until alert("No Boss"). How can add another function to call in sequence immediately after 'bossCheck`?
Added an example to OP not sure how to form code blocks while on mobile. But my question, would that code loop correctly?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.