d0zza Posted April 11, 2017 Share Posted April 11, 2017 (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 April 11, 2017 by d0zza Quote Link to comment Share on other sites More sharing options...
Charlotte Posted April 11, 2017 Share Posted April 11, 2017 How do you expect to click something when there's no action after a condition? Quote Link to comment Share on other sites More sharing options...
d0zza Posted April 11, 2017 Author Share Posted April 11, 2017 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. 1 Quote Link to comment Share on other sites More sharing options...
Vilius Posted April 11, 2017 Share Posted April 11, 2017 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 Quote Link to comment Share on other sites More sharing options...
d0zza Posted April 11, 2017 Author Share Posted April 11, 2017 (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 April 11, 2017 by d0zza Quote Link to comment Share on other sites More sharing options...
Stimpack Posted April 11, 2017 Share Posted April 11, 2017 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 1 Quote Link to comment Share on other sites More sharing options...
Reveance Posted April 15, 2017 Share Posted April 15, 2017 (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 April 15, 2017 by Reveance Quote Link to comment Share on other sites More sharing options...