Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Inventory.deselect() is bugged


    Sicilian7

    Recommended Posts

    As the title implies, Inventory.deselect() is currently bugged. Let's say you are trying to open the bank but you have an item already selected. The following code doesn't work:

    		if (Inventory.isItemSelected()){
    			if (Inventory.deselect()){
    				sleepUntil(() -> !Inventory.isItemSelected(), 2000);
    			}
    		}else{
    			NPC banker = NPCs.closest(npc -> (npc != null && npc.hasAction("Bank")));
    			if (banker != null) {
    				if (banker.interact("Bank")) {
    					sleepUntil(() -> Bank.isOpen(), 3000);
    				}
    			}else{
    				logError("No banker in range!");
    				return -1;
    			}
    		}

    However, the following code does work:

    		if (Inventory.isItemSelected()){
    			if (Inventory.deselect()){
    				sleepUntil(() -> !Inventory.isItemSelected(), 2000);
    			}
    		}
    		NPC banker = NPCs.closest(npc -> (npc != null && npc.hasAction("Bank")));
    		if (banker != null) {
    			if (banker.interact("Bank")) {
    				sleepUntil(() -> Bank.isOpen(), 3000);
    			}
    		}else{
    			logError("No banker in range!");
    			return -1;
    		}

    Basically, the only difference is whether I use two "if" statements vs an "if-else" statement. Yet one of them works and the other doesn't. This sounds like a bug to me.

    Link to comment
    Share on other sites

    why does the bank have anything to do with whether or not u should deselect an item? ur trying to bank ONLY if an item is selected? or u just wrote this code to handle it all in one go? ur script needs to be sectioned out more i think. But atleast u got it working.

    If you wanna make dang sure its bugged. Then use InventoryListener instead. Because that is for sure supposed to record changes in inventory. Where as your If then statement might not get checked quick enough. Save the main loop for ingame entities like your banker there. use listener for inventory.

    e.g.

    public class Script extends AbstractScript implements InventoryListener {
        @Override
        public void onItemChange(Item[] items) {
            if (Inventory.isItemSelected())
                log("oh no an item is selected");
            for (int i=0; i<items.length - 1; i++)
                log(items[i].toString());
        }

    Also. Use Dreambot 3. I've run into many problems with Dreambot 2 for little things.

    EDIT: @Pandemic's response is valid. Yeah you're checking way too quickly if its deselected where as Inventory might not know that yet even though it just did it. You are putting a lot of trust in your program. And not enough wideness. Expect things to go wrong. Because what can go wrong. Will go wrong. Murphy's law.

    Link to comment
    Share on other sites

    That isn't really bugged, it's how Java works. The if/else doesn't re-validate the condition afterwards, so you'd have to check twice (after running deselect) to ensure it has actually been deselected.

     

    Link to comment
    Share on other sites

    3 hours ago, Pandemic said:

    That isn't really bugged, it's how Java works. The if/else doesn't re-validate the condition afterwards, so you'd have to check twice (after running deselect) to ensure it has actually been deselected.

     

    Inventory.deselect() in the first chunk of code doesn't execute at all. It returns false. It does work in the second chunk of code. That does not appear to be the expected behavior, so I still think it's bugged. Whether or not Inventory.deselect() succeeds seems to vary based on where the mouse is when the function is called. 

    In my example, it only worked in the first case because the mouse moves to the Banker and then tries to deselect. In the second case, it just keeps clicking repeatedly  on an invalid location.

    Link to comment
    Share on other sites

    34 minutes ago, Sicilian7 said:

    Inventory.deselect() in the first chunk of code doesn't execute at all. It returns false. It does work in the second chunk of code. That does not appear to be the expected behavior, so I still think it's bugged. Whether or not Inventory.deselect() succeeds seems to vary based on where the mouse is when the function is called. 

    In my example, it only worked in the first case because the mouse moves to the Banker and then tries to deselect. In the second case, it just keeps clicking repeatedly  on an invalid location.

    Is this on DB2 or DB3? If DB3, resizable or fixed mode?

    Link to comment
    Share on other sites

    4 hours ago, Pandemic said:

    Is this on DB2 or DB3? If DB3, resizable or fixed mode?

    Well @Pandemic i would be lying to you if i didn't have these same issues when running every single fishing script on a laggy proxy back on DB2. There is something wrong with the deselect method because Nex Fisher and etc are top tier scripts. and for them to fail that and move on without a care. means something is wrong perhaps. I mean proxy wasn't that laggy at times either just certain times of the day. Still ran into that problem alot across multiple accounts. I would do a deep dive into this. If you are able to stop this from happening again then I will give u a rep and like for every post in this thread. ;). db3 is where its at boys.

    Link to comment
    Share on other sites

    On 9/14/2020 at 2:53 PM, Sicilian7 said:

    As the title implies, Inventory.deselect() is currently bugged. Let's say you are trying to open the bank but you have an item already selected. The following code doesn't work:

    
    		if (Inventory.isItemSelected()){
    			if (Inventory.deselect()){
    				sleepUntil(() -> !Inventory.isItemSelected(), 2000);
    			}
    		}else{
    			NPC banker = NPCs.closest(npc -> (npc != null && npc.hasAction("Bank")));
    			if (banker != null) {
    				if (banker.interact("Bank")) {
    					sleepUntil(() -> Bank.isOpen(), 3000);
    				}
    			}else{
    				logError("No banker in range!");
    				return -1;
    			}
    		}

    However, the following code does work:

    
    		if (Inventory.isItemSelected()){
    			if (Inventory.deselect()){
    				sleepUntil(() -> !Inventory.isItemSelected(), 2000);
    			}
    		}
    		NPC banker = NPCs.closest(npc -> (npc != null && npc.hasAction("Bank")));
    		if (banker != null) {
    			if (banker.interact("Bank")) {
    				sleepUntil(() -> Bank.isOpen(), 3000);
    			}
    		}else{
    			logError("No banker in range!");
    			return -1;
    		}

    Basically, the only difference is whether I use two "if" statements vs an "if-else" statement. Yet one of them works and the other doesn't. This sounds like a bug to me.

     

    In the first instance how quickly do you revaluate that part of script? in my experience isItemSelected cant take up to 1Tick (600ms) before its registers as "Selected" so calling IsSelected too quickly after a selecting an item will ignore it

    Link to comment
    Share on other sites

    2 minutes ago, TheCloakdOne said:

     

    In the first instance how quickly do you revaluate that part of script? in my experience isItemSelected cant take up to 1Tick (600ms) before its registers as "Selected" so calling IsSelected too quickly after a selecting an item will ignore it

    What you said still doesn't explain why the second part of code works and the first doesn't. Both are sleeping the same amonut of time. I will however try adding in a manual sleep of about 1 tick to see if that makes a difference.

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.