|
Post by AkiBot on Jul 19, 2017 5:45:31 GMT
Hello I would like to keep clicking next on the UI to change pages until a particular image is found on the page. However I cant get it to work. Please advise. Thanks
function chooseChapter (chapterNumber)
correctMission = false
while(correctMission == false )
do
click("rightarrow.png")
if find("chapter" .. chapterNumber .. ".png")
then
correctMission = true
else
click("rightarrow.png")
end
end
end
-- timelineBattle()
chooseChapter(4)
|
|
|
Post by AnkuLua on Jul 19, 2017 6:24:19 GMT
Make sure that you have set the correct compareDimension. Make sure following simple script work when the target image on screen.
if exists("target.png") then toast ("found") end
|
|
|
Post by AkiBot on Jul 19, 2017 7:13:44 GMT
these are my settings:
Settings:setCompareDimension(true, 960) Settings: setScriptDimension(true, 960)
I am also able to find the target image. I wanted to know if it is a flaw in my logic when writing the code?
|
|
|
Post by AnkuLua on Jul 19, 2017 10:23:04 GMT
The script should stop when chapter4.png found on the screen.
|
|
|
Post by AkiBot on Jul 19, 2017 16:42:54 GMT
Yes that is what I am hoping for but when I run it. Execution just stops, does not even show any sort of syntax error. I am not sure how to debug this.
|
|
|
Post by AnkuLua on Jul 19, 2017 22:17:45 GMT
In your script, it's normal to stop without any message. You can toast() or print() something in somewhere.
|
|
|
Post by AkiBot on Jul 20, 2017 3:48:56 GMT
Right I mean it stops right after I start executing the script. Nothing happened. It starts and immediately stops. When I use toast() and print() it is able to find the image successfully but nothing happens.
|
|
|
Post by Exilereven on Jul 20, 2017 11:27:56 GMT
That is because you ran it, it ran through your code line by line one time, then ends because the code ends. If you would like for it to repeat a process I recommend looking up using this piece of code:
While true do ----insert what you want to repeat End
Since while is true and stays true until changed by user, it will run that code in a loop. But, if your pic is not on the screen on one of the loops it will probably fail with just using that code. You will need to read up and figure out how to handle what happens if what your searchING for is not present on the screen yet for ankulua to detect it.
|
|
|
Post by AkiBot on Jul 21, 2017 1:43:52 GMT
Okay I see. I will try again thanks. I knew something was wrong with my while loop logic. I will try your method. Thanks.
|
|
|
Post by AkiBot on Jul 21, 2017 2:00:00 GMT
That is because you ran it, it ran through your code line by line one time, then ends because the code ends. If you would like for it to repeat a process I recommend looking up using this piece of code: While true do ----insert what you want to repeat End Since while is true and stays true until changed by user, it will run that code in a loop. But, if your pic is not on the screen on one of the loops it will probably fail with just using that code. You will need to read up and figure out how to handle what happens if what your searchING for is not present on the screen yet for ankulua to detect it. Is my while loop not working the way intended? Ive tried to write it using repeat in lua and cant get it to work. Please advise. I have included a sample of my loop using repeast ... until function chooseChapter (chapterNumber)
repeat
click("rightarrow.png")
if exists("chapter" .. chapterNumber .. ".png") then
print("found")
end
wait(3)
until exists("chapter" .. chapterNumber .. ".png")
end
chooseChapter(4)
|
|
|
Post by Exilereven on Jul 21, 2017 22:39:13 GMT
I'm not sure if you everything setup correctly but I see what your trying to do. This is more like what your going for.
You setup your function, then run that function.
This is just my 2 cents, but you can try something like this.
local chooseChapter = function(chapterNumber)
chapter_find = exists("chapter" .. chapterNumber .. ".png") arrow = "rightarrow.png"
while true do
if chapter_find then toast("found") --break from loop and end script break elseif not chapter_find then click(arrow) --end if end --end while end
--main code start
-- 4 is chapter chosen chooseChapter(4)
I just noticed, if it tries to find arrow to fast and is skipping chapters, just put a small wait (1) right after the click command and adjust wait time according to speed of chapter change animation.
|
|
|
Post by AkiBot on Jul 22, 2017 3:03:34 GMT
I was able to do it with this:
function chooseChapter (chapterNumber) repeat click("rightarrow.png") wait(3) until exists("chapter" .. chapterNumber .. ".png") end
chooseChapter(4)
I found out that the screenshots I took for the chapters had similarities so I took better screenshots. With the new screenshots everything works as is. I am not sure if I am using the Similarity setting correctly. It looks like this for me.
Settings:set("MinSimilarity", 0.95)
Thanks again for your help, much appreciated.
|
|