Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

74
Vistas
Execution of the code is not top to bottom

The execution order does not seem to be correct or I'm missing something.

This is the code:

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
            }
        }
    }
}

findColor

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}
}

The intention of this code is to read json file of colors in hex and assign it to hexColorsArray, iterate through 100x100 images on the screen and trying to find the correct pixel color in that image, if the color is found the image exits. However the issue I'm having is that the console.log("COLOR: " + color) in the function findColor() prints before anything else.

Head of the output:

$ 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
7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.