EMScript Example

Some simple to advanced examples of what you can do with scripting

Simple Image Detection

    //Create a middle region
    var region = Region.deviceReg().middle()

    //Find the image
    var result = region.find("template", 5000)

    if (result) {
        var score = result.getScore()
        var point = result.getPoint()

        result.click() //or just use the click method
    } else {
        
    }

Multiple Image Detection

    //Create a middle region
    var region = Region.deviceReg().middle()

    //Find all the images at once
    var results = region.findAll(["template 1", "template 2", "template 3"], 5000)

    if (results) {
        for (var i = 0; i < results.size; i = i + 1) {
            var result = results[i]
            //do something with the result
        }
    } else {
        
    }

Swipe between Images

    //function to create swipe path from image result
    fun createPath(results) {
        var path = []
        for (var i = 0; i < results.size; i = i + 1) {
            var result = results[i]
            var swipePoint = SwipePoint(result.getPoint())
            path.push(swipePoint)
        }

        return path
    }

    //Create a middle region
    var region = Region.deviceReg().middle()

    //Find all the images at once
    var results = region.findAll(["template 1", "template 2", "template 3"], 5000)

    if (results) {
        //create the path link all images
        var path = createPath(results)

        //swipe along the path
        swipe(path)
    } else {
        
    }

Click till something appear/disappear

    //Useful for clearing victory screen for example

    var region = Region.deviceReg().middle() //middle region
    var result

    //while the element is NOT found or you can flip it
    while(!(result = region.find("something indicate the screen is cleared"))) {
        //we click or anything you want to do in this block
        click(Point(500, 500))
    }

Left Right Loop

    //Useful for AE or any game that need to do something until something appear
    //Assume you have already made a goLeft and goRight function

    var reverse = false //use to switch left and right
    var region = Region.deviceReg().middle() //middle region

    do {
        //alternating between left and right
        if (reverse)
            goRight()
        else goLeft()

        var result = region.find("Something indicate we entered battle")

        //if enter battle then get out of the loop
        if (result)
            break
        else
            reverse = !reverse //switch
    } while(true)

© 2024 - Macrorify by KoK-CODE