TheCloakdOne 389 Share Posted June 15, 2020 Hey all, Ive been watching a few of my bots recently and for some reason they will do this weird thing where it goes back and forward hovering over the inventory items, i was just wondering if anyone had encountered this before and if so what caused it? Im guessing its due to scanning the inventory for an item in my loop? if this is the case what is the best practice for handling this? i was hoping to avoid having to use hashmaps to track the current inventory contents. Example: Link to comment Share on other sites More sharing options...
Neffarion 486 Share Posted June 15, 2020 49 minutes ago, thecloakdone said: Hey all, Ive been watching a few of my bots recently and for some reason they will do this weird thing where it goes back and forward hovering over the inventory items, i was just wondering if anyone had encountered this before and if so what caused it? Im guessing its due to scanning the inventory for an item in my loop? if this is the case what is the best practice for handling this? i was hoping to avoid having to use hashmaps to track the current inventory contents. Example: I havent seen this happening, what code are you using Link to comment Share on other sites More sharing options...
TheCloakdOne 389 Author Share Posted June 15, 2020 Its private script doing some Quests, been doing some debugging this morning and it looks like its caused by the below line (presumable due to checking the name) getInventory().contains("Coins") || getInventory().contains((i) -> i.getName().equals("Clay") && i.isNoted()) Ill try this with ID implementation instead of Strings and see if that resolves, i remember seeing this issue on startup on another script a while back (would hover over all items in inventory once on startup) but i cannot remember what caused it Link to comment Share on other sites More sharing options...
TheCloakdOne 389 Author Share Posted June 15, 2020 UPDATE: Found the issue, turns out im just a moron, this was being called in a submethod on loop. return getInventory().get(item -> item != null && item.getName().contains("pickaxe") && this.canUsePick(item.getName())) != null; Looks like by calling get it will hover the item? Changed to this and it doesnt happen anymore: return getInventory().contains((i) -> i.getName().contains("pickaxe") && this.canUsePick(i.getName())); Link to comment Share on other sites More sharing options...
Neffarion 486 Share Posted June 15, 2020 Using Inventory get() doesn't hover anything. Not sure what it could be doing that in your case. Also, I would null check the contains item before doing any of those checks Link to comment Share on other sites More sharing options...
TheCloakdOne 389 Author Share Posted June 15, 2020 I isolated it to just that line of code and its causing it... ill build a reproduction script later. Why do i have to check null within the filter? if there isnt any items in the inventory it would be an empty filter loop no? by casting to i i know its not null Link to comment Share on other sites More sharing options...
Neffarion 486 Share Posted June 15, 2020 2 minutes ago, thecloakdone said: I isolated it to just that line of code and its causing it... ill build a reproduction script later. Why do i have to check null within the filter? if there isnt any items in the inventory it would be an empty filter loop no? by casting to i i know its not null Items can be null if they dont exist (kinda weird but yea) Link to comment Share on other sites More sharing options...
TheCloakdOne 389 Author Share Posted June 15, 2020 Thats super odd, i was under the impression Contains returned an Interface? in which case i shouldnt need to check for null? The 2 methods will return default ID (0) or String ("") from what i read here: https://dreambot.org/javadocs/org/dreambot/api/wrappers/interactive/Identifiable.html Link to comment Share on other sites More sharing options...
Neffarion 486 Share Posted June 15, 2020 10 minutes ago, thecloakdone said: Thats super odd, i was under the impression Contains returned an Interface? in which case i shouldnt need to check for null? The 2 methods will return default ID (0) or String ("") from what i read here: https://dreambot.org/javadocs/org/dreambot/api/wrappers/interactive/Identifiable.html getInventory().contains() returns a Boolean Identifiable is an interface which all items have, but they can be null themselves. Example: Empty inventory slots are null Items Link to comment Share on other sites More sharing options...
TheCloakdOne 389 Author Share Posted June 15, 2020 Yeah i get that but why would getInventory return a list of 28 null Items? would it not just return an empty list? so when it comes to the contains loop if the underlying list is empty its not going to null? Just trying to figure out whats going on behind the scenes of the API, as i dont have null checks in any of the Filter implementations and i havent seen a NPE yet (trying to work out if this is a fire waiting to start or not) Coming from a Golang background and havent touched Java professionally for 6 years so getting back up to scratch! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.