ATG
Junior Member
Posts: 79
|
Post by ATG on Aug 15, 2020 11:11:22 GMT
need some advice on how to make sure drag and drop actually performed. the script of mine, the drag and drop failed to do what i wanted.
small scenario: 1.finish boss 2. click exit button 3. wait 13 second --waiting finish loading and show boss map 4. swipe screen -- slight up right to find next boss on boss map 5. click on boss
NOTE: usually 8 second could load everything properly but i give extra seconds just to make sure. even though with more wait time drag and drop sometime may not do what i want.
the problem im facing in step 3 and 4. step 4 failed to drag and drop some time in my script.
wait (13)
setDragDropTiming(100, 100) setDragDropStepCount(50) dragDrop(Location(753,206), Location (549,421)) is there way to use usePreviousSnap() to check if the screen is the same after waited 13 seconds, then perform drag and drag?
to solve that, i came up to use usePreviousSnap() . below the code, but im not sure is that suppose the right way to do?
after_boss1.png >> is the image which i captured how it is like after waited 13 seconds. basically, if the image is same after waited 13 second, then do drag and drop..
the reason of using else, just to make sure somehow that the if statement is not doing as expected, then the next drag and drop will executed.
snapshot() usePreviousSnap(true) if (exists( "after_boss1.png" ))then print ("first swipe") setDragDropTiming(100, 100) setDragDropStepCount(50) dragDrop(Location(753,206), Location (549,421))
else print ("second swipe") setDragDropTiming(100, 100) setDragDropStepCount(50) dragDrop(Location(753,206), Location (549,421))
end usePreviousSnap(false)
Hope someone can give me guidance?
thank you
|
|
|
Post by Exilereven on Aug 15, 2020 21:55:04 GMT
You could use save(), then compare to it later in script.
--using DebugMyScript in this example btw --make sure you setup DIR_TEMP to your own temp folder, and also set it back to original image path at the bottom. but this will check the region for a certain time/score until it changes.
--EX: if isSameSpot(3,.90) then --do stuff here end --this will see if the spot changes within 3 seconds using .90 score for match.
--you will need to setup your own region as well.
function isSameSpot(t, s) s = s or 0.9 t = t or 1.5 local result = false setImagePath(SYS.DIR_TEMP) --prset your teml folder before calling REG.samespot:save('_sp.png') --setuo your own region wait(t) snapshot()
if Image:R(REG.samecheck):exists('_sp.png', 0) then if Image:getData('score') > s then --here mesns if image score is .90 or higher return true result = true end end usePreviousSnap(false) setImagePath(SYS.DIR_IMAGES) --reset original image path return result end
|
|
ATG
Junior Member
Posts: 79
|
Post by ATG on Aug 16, 2020 0:45:10 GMT
Hi exilereven,
regarding this line:
if Image:R(REG.samecheck):exists('_sp.png', 0) then REG.samecheck, do you mean the same as REG.samespot?
if I changed to REG.samespot then I have faced another issues on this line
if Image:getData('score') > s then about the 'score' this number got from where to compare with s ?
error i got is : attempt to compare number with table
|
|
ATG
Junior Member
Posts: 79
|
Post by ATG on Aug 16, 2020 9:29:09 GMT
if Image:R(REG.samecheck):exists('_sp.png', 0) then if Image:getData('score') > s then --here mesns if image score is .90 or higher return true result = true end
if Image:R(REG.images.samespot):exists('_sp.png', 0) then local d = Image:getData() if d.score > s then --here means that if image score is .90 or higher return true result = true end end
|
|
|
Post by Exilereven on Aug 16, 2020 16:51:11 GMT
This is a stripped version, hope this helps.
ROOT = scriptPath() IMAGES = ROOT .. 'images/' DIR_TEMP = ROOT .. 'temp/' --from where your script starts, create a folder called images, and one called called temp
local save_image_area = Region(0,0,0,0) --fill in region numbers for exact image area you want saved. local image_check_area = Region(0,0,0,0) --make this area, the area to check for the image we saved, so make atleast larger than save area.(like setting a region slightly bigger than the image area for searching) function isSameSpot(t, s) s = s or 0.9 t = t or 1.5 local result = false setImagePath(DIR_TEMP) --set your temp folder before calling save to not save_image_area:save('_sp.png') wait(t) snapshot()
if image_check_area:exists('_sp.png', 0) then if getLastMatch():getScore() > s then --here mesns if image score is .90 or higher return true result = true end end usePreviousSnap(false) setImagePath(IMAGES) --reset original image path return result end
--EXAMPLE USAGE:
if not isSameSpot() then --if it the area has changed then do stuff, else just move on looping code. else --if it has not changed then do other stuff here end
|
|
ATG
Junior Member
Posts: 79
|
Post by ATG on Aug 16, 2020 22:10:02 GMT
This is a stripped version, hope this helps. Thanks exilereven for your sample code. I've an idea now and I really learn a lot from your codes too.
but, FYI.
if getLastMatch():getScore() > s This line gives error of "attempt to index a boolean value"
It seem getLastMatch() returns boolean, which i tested it. there is no way to compare boolean to integer.
To resolve that I still uses this as below because it seems getData() give us the score number.
local d = Image:getData() if d.score > s
|
|
ATG
Junior Member
Posts: 79
|
Post by ATG on Aug 16, 2020 22:32:15 GMT
further testing, Now I've resolved the error of boolean . need to wrap around the code with Image:
EDIT: can run without the Image:
I guess you forgot to include image_check_area before getLastMatch():getScore()
It took me very long time to figure it out
if image_check_area:exists('_sp.png', 0) then if image_check_area:getLastMatch():getScore() > s then result = true
|
|
|
Post by Exilereven on Aug 17, 2020 0:43:24 GMT
Yup my bad, forgot to include a region for getlastmatch, from mobile in a rush lol. Sorry.
|
|