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
  • Stupid garbage value


    JAG98

    Recommended Posts

    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

    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

    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.