El orden de ejecución no parece ser correcto o me falta algo.
Este es el código:
function main() { helper.openRS() console.log("START") let hexColorsArray = helper.readColorData() let startX = 0 let startY = 627 let areaX, areaY = 100 let found = false console.log(itemData.grotworm.colors) while(!found) { colorFound = helper.findColor(startX,startY,areaX,areaY, hexColorsArray) console.log("StartX: " + startX + ", StartY: " + startY) if(colorFound.state) { found = true console.log("Color Found?: " + colorFound.state) robot.moveMouse(colorFound.random_x, colorFound.random_y) robot.mouseClick() } else { if (startX + 100 >= 1920) { startX = 263 startY -= 100 } else if (startY < 5) { found = true } else { startX += 100 } } } }encontrarColor
function findColor(x,y,width,height, colors) { let img = robot.screen.capture(x, y, width, height); let test = width * height let random_x = 0 let random_y = 0 let color = [] for (let i = 0; i < test; i++) { random_x = getRandomInt(0, width-1); random_y = getRandomInt(0, height-1); color = img.colorAt(random_x, random_y) console.log("COLOR: " + color) if (colors.includes(color)) { return {"random_x": random_x + x,"random_y": random_y + y,"state": true}; } } return {"random_x": 0, "random_y": 0,"state": false} }La intención de este código es leer el archivo json de colores en hexadecimal y asignarlo a hexColorsArray, iterar a través de imágenes de 100x100 en la pantalla e intentar encontrar el color de píxel correcto en esa imagen, si se encuentra el color, la imagen sale. Sin embargo, el problema que tengo es que console.log("COLOR: " + color) en la función findColor() se imprime antes que cualquier otra cosa.
Jefe de la salida:
$ npm start > test@1.0.0 start > node main.js COLOR: 202020 COLOR: d8eafa COLOR: 202020 COLOR: 202020 COLOR: 202020 COLOR: 202020 COLOR: ffd253 COLOR: 202020 COLOR: 202020 COLOR: 202020 COLOR: 202020 COLOR: 202020 COLOR: 202020 COLOR: 202020 COLOR: 202020 COLOR: 202020 COLOR: e9e9e9