Jump to content

getMouse.click not working


Recommended Posts

Posted (edited)

I'm trying to use getMouse().click but it doesn't seem to be clicking when I want it to.

My code is as follows:

for (i = 0; i < 28; i++) {
	if (InventorySlotDestination.getSlot(i).contains(getMouse().getPosition())) {
		if (getMouse().click(false)) {
			i++;
			sleep(random(100, 125));
		}
	} else {
		Rectangle rect = InventorySlotDestination.getSlot(i);
		getMouse().move(rect.x + (rect.width / 2), rect.y + (rect.height / 2));
		sleep(random(100, 125));
	}
}

Basically I'm just trying to click on all items in my inventory, my mouse moves through the inventory as intended but doesn't click on anything.

I don't want to use inventory.interact() as that doesn't serve the right purpose for what I want to do.

Edited by d0zza
Posted
4 minutes ago, Charlotte said:

How do you expect to click something when there's no action after a condition?

This line here:
if (getMouse().click(false)) {

should be clicking the mouse, just because I have it in an if statement doesn't mean its not going to do anything. getMouse().click() is a boolean function that returns true if the mouse is clicked or false if it isn't.

  • Like 1
Posted
39 minutes ago, d0zza said:

This line here:
if (getMouse().click(false)) {

should be clicking the mouse, just because I have it in an if statement doesn't mean its not going to do anything. getMouse().click() is a boolean function that returns true if the mouse is clicked or false if it isn't.

Well it should be clicking correctly, most likely the first if statement is wrong.

But Im guessing you want it to shif click drop, which osbot already does if you enable it in game :b

Posted (edited)
2 hours ago, Vilius said:

Well it should be clicking correctly, most likely the first if statement is wrong.

But Im guessing you want it to shif click drop, which osbot already does if you enable it in game :b

Oh fuck me I know why, I should be using a while loop, not a for loop

Edited by d0zza
Posted

try this

for (int i = 0; i < 28; i++) {
    if (getMouse().click(getInventory().getMouseDestination(i))) {
        sleep(random(100, 125));
    }
}

you can decrement i if it fails to click the slot, but that may produce weird results

also may want to check if there's an item at slot unless you want it to click empty slots

  • Like 1
Posted (edited)

It doesn't click because you're wasting your index on moving to the slot :P then the next loop it will come in the first else again, moving to the next...but the first if statement never gets executed...
 

for (i = 0; i < 28; i++) {
	if (InventorySlotDestination.getSlot(i).contains(getMouse().getPosition())) {
		//...never gets in here, because this is the next slot...why would the mouse already be there?
	} else {
		//...always executes this to move to the next
	}
}

so basically you want something like

for (i = 0; i < 28; i++) {
	if (!InventorySlotDestination.getSlot(i).contains(getMouse().getPosition())) {
		Rectangle rect = InventorySlotDestination.getSlot(i);
		if (getMouse().move(rect.x + (rect.width / 2), rect.y + (rect.height / 2))) {
			sleep(random(100, 125));
		}
	}

	if (InventorySlotDestination.getSlot(i).contains(getMouse().getPosition())) {
		if (getMouse().click(false)) {
			// i++; this one isn't necessary unless you want to skip
			// items
			sleep(random(100, 125));
		}
	}
}

But anyways, as Stimpack already said, it's easier to let the osbot api do all that for you by using 

getMouse().click(getInventory().getMouseDestination(i))
Edited by Reveance

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...