ATG
Junior Member
Posts: 79
|
Post by ATG on Aug 1, 2020 8:02:30 GMT
Below is the partial of my code.
the function is working alright but one issue I have is the "Image:existsClick(btnExit, 240)"
normally, it will wait until the boss stage is completed and load the next screen with Exit button. Sometime the click has already clicked but the emulator freezes or slow loading due to performance issues, it misses out and the exit button is still remain on the screen.
How do I go about to make sure the exit button will be click again? somehow I couldn't think of a way to handle this issues. the mentioned issues hardly happened but I want to make sure it is fixed.
please kindly help.
dofile (scriptPath() .. "DebugMyScript.luac")
function doCampaign1(boss) local bossOnMap = boss --click on boss Image:existsClick(bossOnMap) --wait 3 second for start battle button on next screen wait(3) --click on start battle button when found. Enter inside the boss battle, 4 minute count down timer to complete. when completed, exit button will show Image:existsClick(btnStartBattle) --Click on Exit to quit campaign Image:existsClick(btnExit, 240)
end --end doCampaign
-- main program
boss = "abc.png" if exists(boss) then doCampaign1(boss) end
|
|
|
|
Post by Mercobots on Aug 1, 2020 12:21:29 GMT
hi there just put your button in a loop something like this
repeat toast('exit) until not Image:existsClick(btnExit, 240)
or take a pic from next stage after the button disappear and wait for it
repeat Image:existsClick(btnExit) until Image:exists('next_img_stage', 240)
|
|
ATG
Junior Member
Posts: 79
|
Post by ATG on Aug 1, 2020 21:09:02 GMT
Thanks Mercobots.
However, both loop not doing what i expecting.
first loop, it unable to exit the repeat loop after the btnExit is found and clicked. Thus, it won't execute the next line of code.
second loop, it didn't exit the stage, so won't able to look for other stage.
maybe I should add some wait time and add double click to make sure it is clicked?
Another question, which is not relevant about the clicks. but i want to know how advanced scriptors activate their skill actions when inside the stage? if you don't mind telling me (or show some sample) the correct way of doing it? currently my script only do normal attacks.. do you guys use loops to do constant check and activate them?
Image:existsClick(btnStartBattle)
--between the line of code. use loop to constantly activate skills?
Image:existsClick(btnExit, 240)
|
|
|
Post by Mercobots on Aug 1, 2020 23:11:51 GMT
Thanks Mercobots.
However, both loop not doing what i expecting.
first loop, it unable to exit the repeat loop after the btnExit is found and clicked. Thus, it won't execute the next line of code.
second loop, it didn't exit the stage, so won't able to look for other stage.
maybe I should add some wait time and add double click to make sure it is clicked?
Another question, which is not relevant about the clicks. but i want to know how advanced scriptors activate their skill actions when inside the stage? if you don't mind telling me (or show some sample) the correct way of doing it? currently my script only do normal attacks.. do you guys use loops to do constant check and activate them?
Image:existsClick(btnStartBattle)
--between the line of code. use loop to constantly activate skills?
Image:existsClick(btnExit, 240)
hi, i can guarantee you the loops will work for sure , and for what i see on your code is all about the timeout search ... let me explain the better i can so for 1º loop repeat toast('exit) until not Image:existsClick(btnExit, 240)
this chunk of code will repeat until btnexit is no longer visible whit a search timeout of 240 seconds(4 minutes) , so far so good! but your script will do the following -> btnexit found click, repeat -> btnexit NOT found , wait 4 minutes and continue cuz the script is lookink for btnexit until 4 minutes has passed so i recommend you to do the following to be sure ! if Image:existsClick(btnExit, 240) then toast('exit found') repeat toast('exit') until not Image:existsClick(btnExit, 0) end
there is another function i forgot to mention because i don't use it at all but is good for you to take look at it too waitVanish() ankulua.boards.net/thread/6/objects-methods-introduction-sikuli-compatible#waitVanishAnother question, which is not relevant about the clicks. but i want to know how advanced scriptors activate their skill actions when inside the stage? if you don't mind telling me (or show some sample) the correct way of doing it? currently my script only do normal attacks.. do you guys use loops to do constant check and activate them?not sure what you are asking for, but i organize my code using function when i need to repeat actions over and over and sure i use a main loop to constant check and repeat everthing
|
|
ATG
Junior Member
Posts: 79
|
Post by ATG on Aug 2, 2020 7:15:40 GMT
Hi Mercobots,
Sorry, I think I may have confused you.
Actually, when btnExit is found it must stop and shouldn't be repeat. then on the main part, it will call another function to do boss again.
FYI, 4 minute was the time limit it must finish the stage and display Exit button on screen. if cant finish within the 4 min it will failed. in most cases, in my case, auto play to kill can finish within 40 second. The reason I put to wait for 4 minute was for longer window period.
With your sample codes on repeat loop it give me some sights ( i thought it must use boolean variable to stop the condition, everyday I learnt sth new ) . With that knowledge, I've make some modifications and seem to work now. May not be perfect, but so far so good! finger cross!. Also, I was able to reduce many wait() function. Before, I have to wait for some period to ensure the screen is load properly and with certain buttons pop up then it will click to avoid muck up
Please have a look and see whether it is okay? if there can be room for more improvement, please let me know.
function playBoss4() if Image:exists(boss_A) then repeat toast ("click on boss") Image:existsClick(boss_A) until Image:exists(btnStartBattle, 60) if Image:exists(btnStartBattle) then repeat toast ("found start battle") Image:existsClick(btnStartBattle) until Image:existsClick(btnStartBattle,30) repeat toast ("inside battle, waiting to kill boss and exit") Image:existsClick(btnExit) until Image:existsClick(btnExit,240) end end
wait(10)
end
|
|
|
Post by Exilereven on Aug 2, 2020 17:42:00 GMT
Those toasts are going to slow you way down. Try turning them into prints instead and run it.
|
|
|
Post by Mercobots on Aug 2, 2020 20:06:12 GMT
hi there So i prepared a small chunk of code to give a better idea how this works, with the given information of course , i don't know the game we are talking about and how its works must of lines are commented and i mixed some loops to show some others possibilities too! But the must important of this code is the ability to search and check images whit a timeout of 0, you will notice you don't need wait times at all ! -- This help keeping track of the script -- change the region R_log as you need - Region(x, y, width, height) local R_log = Region(0, 0, 500, 50) local function log(text) text = text or '' R_log:highlightOff() R_log:highlight(text) end
-- i don't know what game it is and how it works , but i presume all boss fights are identicals if not the same mecanic, -- so you only need a function to do the job and pass as parameter the boss name image local function atkBoss(boss)
log('Looking for ' .. boss)
if Image:exists(boss .. '.png', 0) then log(boss .. 'found')
-- will look until btnStartBattle appears on screen before continue script -- on all loops we set all timeouts to 0 to speed up the search since the script can't procede until it find the image while not Image:existsClick(btnStartBattle, 0) do log("Search start btn") if Image:existsClick(boss_A, 0) then log("click on boss") end end
-- log("found start battle btn") -- -- at this stage the script already know the btnStartBattle is visible -- now let be sure it vanish from screen repeat log("awaiting start battle btn vanishes") until not Image:existsClick(btnStartBattle, 0)
-- now the battle started for sure cuz battle btn vanishes log("Starting battle")
-- here you use 240 seconds and i know why, but using a timeout 0 the script will know almost instantly the boss is dead while not Image:existsClick(btnExit, 0) do log("inside battle, waiting to kill boss and exit") end
log("boss is dead") -- the boss is dead cuz btnExit is on screen, from here we just need to be sure btnexit vanish as well repeat log("awaiting btnExit vanishes") until not Image:existsClick(btnExit, 0)
return true end
log(boss .. ' not found') return false end
-- your main loop, you can now search and atack multiples bosse using the same funciton while (true) do atkBoss(boss_A) atkBoss(boss_B) atkBoss(boss_C)
-- dont forget attkboss() return boolean value (true false) so you can use it that way if atkBoss(boss_A) then -- code elseif atkBoss(boss_B) then -- code elseif atkBoss(boss_C) and atkBoss(boss_D) then -- code end end
Just let me know how that works for you
|
|
ATG
Junior Member
Posts: 79
|
Post by ATG on Aug 3, 2020 3:49:18 GMT
... But the must important of this code is the ability to search and check images whit a timeout of 0, you will notice you don't need wait times at all !... Thank you Mercobots.
your codes work beautifully and perfectly.
I've applied similar logic to some part of my script and is working nicely too, which esp the buttons.
Once again, thank you very much
|
|