JAG98 4 Share Posted March 5, 2021 Pretty damn sure this is a very simple issue my adhd brain isn't able to find a work-around for. A simple potato picker script. CANNOT get the correct value for potatoes picked to be displayed! Spoiler if(finalCount<28){ if(!Inventory.isEmpty()){ graphics.drawString("Potatoes picked: "+Inventory.count("Potato"), 10, 75); finalCount= Inventory.count("Potato"); } } else{ if(!Inventory.isEmpty()){ finalCount+= Inventory.count("Potato"); graphics.drawString("Potatoes picked: "+finalCount, 10, 75); } } The moment inventory is full, shit hits the fan and all that is shown is never stopping count for Potatoes picked. Conversely also tried another approach without Inventory checks. Same result. Another approach without the finalCount check didn't help either. tl;dr looking for a snippet of code that keeps track of the amount of potatoes farmed after Inventory is full and later when Inventory is empty, doesn't lose track or doesn't get reset after each Inventory cycle. Any help will be much appreciated! Link to comment Share on other sites More sharing options...
TheCloakdOne 389 Share Posted March 5, 2021 Your best off using an inventory listener for something like this: On your `Main` Add Import: import org.dreambot.api.script.listener.InventoryListener; Adjust your class and add implements InventoryListener: public class Main extends AbstractScript implements InventoryListener Add the following code to count the potatos @Override public void onItemChange(Item[] items) { for (Item i : items) { if (i.getAmount() <= 0 || !i.getName().equals("Potato")) continue; finalCount += i.getAmount(); //Add the amount (would be 1 in this case) to our finalCount each time we detect an inventory change } } Then in your paint just do: graphics.drawString("Potatos Picked: " + finalCount, 10,75) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.