Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Simply clicking

Joined
Dec 18, 2014
Messages
398
I'm sorry if this is basic, but I'm getting very frustrated because something that should be absurdly simple is not working out.

For some reason, with the following code, the mouse would have an approximately 1/3 chance of not pulling the second click off and skipping directly to that last part of the code. The mouse always moves right next to the actual SpriteItem, without getting to it.

SpriteItem arrowShafts;
SpriteItem feathers;

if(Inventory.containsAllOf(ARROW_SHAFT_ID, FEATHER_ID))
{
arrowShafts = Inventory.getItems(ARROW_SHAFT_ID).first();
feathers = Inventory.getItems(FEATHER_ID).first();
}

arrowShafts.click();
// Execution.delay(56, 256, 128);

feathers.click();
// Execution.delay(56, 256, 128);

Execution.delayUntil(() -> someInterface.isVisible(), 400, 800);
Keyboard.typeKey(" ");

I tried amending this with various constructs, such as

Execution.delay,
surrounding the clicks with if statements,
clicking the interactable bounds instead of the SpriteItem itself,
delayUntil() -> feathers.click().

None of them made any difference except the last one, which caused problems by clicking more than once every time. Is the mouse is clicking on the edge of the inventory slot without clicking on the SpriteItem itself? Is there a way to ascertain that the second click will happen?
 
Last edited:
Joined
Dec 10, 2014
Messages
3,332
I'm sorry if this is basic, but I'm getting very frustrated because something that should be absurdly simple is not working out.

For some reason, with the following code, the mouse would have an approximately 1/3 chance of not pulling the second click off and skipping directly to that last part of the code. The mouse always moves right next to the actual SpriteItem, without getting to it. I tried using

Execution.delay,
surrounding the clicks with if statements,
clicking the interactable bounds instead of the SpriteItem itself,
delayUntil() -> feathers.click().

None of them made any difference except the last one, which caused problems by clicking more than once every time. Is the mouse is clicking on the edge of the inventory slot without clicking on the SpriteItem itself? Is there a way to ascertain that the second click will happen?


SpriteItem arrowShafts = // get from Inventory
SpriteItem feathers = // get from Inventory

arrowShafts.click();
// Execution.delay(56, 256, 128);

feathers.click();
// Execution.delay(56, 256, 128);

Execution.delayUntil(() -> someInterface.isVisible(), 400, 800);
Keyboard.typeKey(" ");

if (shafts are selected){
if(feathers.click()){
delay until interface;
send space;
}
} else {
select feathers;
}
Maybe try something like that instead?
 
Joined
Dec 18, 2014
Messages
398
Thanks. Just had to add more conditions, like Hax said, and split everything into different methods to enable the loop to start over. The clicks still fail 1/3 of the time, but the loop starts over if that happens.
Code:
@Override
    public void onLoop()
    {
        clickSpriteItems();
        Execution.delayUntil(() -> addFeather.isVisible(), 400, 800);
        getAddFeather();
        if(addFeather.isVisible())
        {
        Keyboard.typeKey(" ");
        Execution.delayUntil(() -> count >= 9);
        count = 0;
        }
        else
        {
            return;
        }
        Execution.delay((long)Random.nextGaussian(0, 20260, 256, 0.477));
    }
  
    public void clickSpriteItems()
    {
        getSpriteItems();
        if(Inventory.getSelectedItem() != null)
        {
            Inventory.getSelectedItem().getBounds().click();
        }
        if(arrowShafts.getInteractionPoint().click())
        {
            Execution.delay((long) Random.nextGaussian(56, 256, 128));
            System.out.println("click");
            if(feathers.getInteractionPoint().click())
            {
                Execution.delay((long) Random.nextGaussian(56, 256, 128));
                System.out.println("click");
                Execution.delay(500);
                getAddFeather();
            }
        }
    }
 
Engineer
Joined
Jul 28, 2013
Messages
2,776
As a note, the logic shown in this thread is rather bad and prevents the script from being able to "humanly" handle many situations. For example, if interacting with the arrow shafts is successful but then it fails to interact with the feathers, it will deselect the arrow shafts, reselect them, and then repeat the process. Also, you can and should be directly interacting with the sprite items, not necessarily the bound or point objects. This is because interacting with the objects themselves occasionally has special per-entity behavior.
 
Joined
Dec 18, 2014
Messages
398
As a note, the logic shown in this thread is rather bad and prevents the script from being able to "humanly" handle many situations. For example, if interacting with the arrow shafts is successful but then it fails to interact with the feathers, it will deselect the arrow shafts, reselect them, and then repeat the process. Also, you can and should be directly interacting with the sprite items, not necessarily the bound or point objects. This is because interacting with the objects themselves occasionally has special per-entity behavior.
Yes, I was unaccustomed to the client's execution of the API and was frustrated at unsuccessful clicks returning true. I think I've improved and hope you can give me feedback on the logic in my Nature Altar Runner, which I will submit tomorrow in a messy state, but which will be cleaner and more conceptually sound in the commit after that. I will also improve this script tomorrow.
 
Last edited:
Top