Jump to content

Welcome to DreamBot!

Download for Free

Supercharge Your Bots

Run unlimited bots today using DreamBot's Covert Mode and
stay more protected.

Upgrade Now
Frequently Asked Questions
  • Are you not able to open the client? Make sure you have Java installed
  • 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 gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
Bottinghub.com

Interested in advertising your business? Reach out today!

Sicilian7

Inventory.deselect() is bugged

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.

Share this post


Link to post
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.

Edited by LordJashin32

Share this post


Link to post
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.

Edited by Sicilian7

Share this post


Link to post
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?

Share this post


Link to post
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.

Edited by LordJashin32

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...