|
Post by hoanglenin on Jul 28, 2022 6:12:32 GMT
Hi!
I am facing a problem. Ihave 60 different images(pic1.png to pic60.png) and on the game screen will randomly show 10-15 images each time. I want to print these images in order from left to right example: the images appear in the order pic5.png,pic20.png, pic3.png.... respectively the output will be P5, P20,P3.... same as numberOCR() I have not found any solution for this Can you help me? thank you!
|
|
|
Post by AnkuLua on Jul 28, 2022 12:15:55 GMT
Use lua table.sort() to sort a table. Here is one example function
function regionSortByX(data) local sortFunc = function(a, b) return (a:getX() < b:getX()) end table.sort(data, sortFunc) return data end
|
|
|
Post by hoanglenin on Jul 30, 2022 15:05:01 GMT
Use lua table.sort() to sort a table. Here is one example function function regionSortByX(data) local sortFunc = function(a, b) return (a:getX() < b:getX()) end table.sort(data, sortFunc) return data end
thanks for the reply! I want to ask a few more things. data is the table containing the images found on the screen?
|
|
|
Post by AnkuLua on Jul 30, 2022 15:56:41 GMT
data is the table containing matches of the images
here is an untested example
allMatches = {}
for i = 1, 60 do local image = "pic" .. i .. ".png" local matches = findAllNoFindException(image) for k, m in ipairs(matches) do table.insert({match = m, pic = image}) end end
function regionSortByX(data) local sortFunc = function(a, b) return (a.match:getX() < b.match:getX()) end table.sort(data, sortFunc) return data end
sortedMatches = regionSortByX(allMatches)
for i, d in ipairs(sortedMatches) do print(i, d.match:getX(), d.pic) end
|
|
|
Post by hoanglenin on Aug 1, 2022 13:34:30 GMT
data is the table containing matches of the images here is an untested example allMatches = {}
for i = 1, 60 do local image = "pic" .. i .. ".png" local matches = findAllNoFindException(image) for k, m in ipairs(matches) do table.insert({match = m, pic = image}) end end
function regionSortByX(data) local sortFunc = function(a, b) return (a.match:getX() < b.match:getX()) end table.sort(data, sortFunc) return data end
sortedMatches = regionSortByX(allMatches)
for i, d in ipairs(sortedMatches) do print(i, d.match:getX(), d.pic) end
it work well bro! thank u
|
|