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
  • Widget issues


    Deep Slayer

    Recommended Posts

    Hi all,
     

    How do I avoid getting a null from a widget that isn't there?


    So what I'm trying to do is check if a window is open.

    But if the screen that I'm looking for is not open and I go to check if the Widget is not null.. it still throws a null? - because obviously the widget isn't open.

     

    if(Widgets.getWidget(number1).getChild(number2)!=null)

    maybe My logic is wrong? 

     

    What I'm trying to do is check if a screen is open when it is not open. Does that make sense?

    I'm looking for a way to do this ^^

     

    Link to comment
    Share on other sites

    WidgetChild example = Widgets.getWidgetChild(1, 1);
    
    if (example != null && example.isVisible()) {
      //do stuff
    } else {
      // open window
    }

     

    Link to comment
    Share on other sites

    Hey RetroBot,

    Thanks for your reply. I've tried this to check if its visible and != null. 

    It still throws a Null pointer exception if I try to find the widget and it doesn't exist.

    I'm not sure what the logic is supposed to be

    Link to comment
    Share on other sites

    if(Widgets.getWidget(446).getChild(35)!=null && Widgets.getWidget(446).getChild(35).isVisible()) {
        
    
    }

    this will throw an error if it can't find the widget - My thinking is that it should just skip this if statement if it cant find the widget?

    Link to comment
    Share on other sites

    2 hours ago, Deep Slayer said:
    
    
    if(Widgets.getWidget(446).getChild(35)!=null && Widgets.getWidget(446).getChild(35).isVisible()) {
        
    
    }

    this will throw an error if it can't find the widget - My thinking is that it should just skip this if statement if it cant find the widget?

    You're not doing something right and you probably have the wrong widget. You should do this like so:

    <

    WidgetChild randomWidg = Widgets.getWidgetChild(0,0,0);
    if(randomWidg != null){
        log("Interact with widget.");
        randomWidg.interact();
    }


    Also use the game explorer to make sure the widget you're using has the action you need.

    Link to comment
    Share on other sites

    Try null checking the parent first, see if that works. Like so:

     

    [code]

    WidgetChild ourWidgetChild= Widgets.getWidget(446) != null ? Widgets.getWidgetChild(446,35) : null;
    if (ourWidgetChild != null && ourWidgetChild.isVisible()) {
    

    //do shit

    }

    /code]

    Link to comment
    Share on other sites

    Thanks for the help!

    Issue has been solved. I have been using this guide to use my widgets: 


    I think it may be out of date because in chapter 2, he explains to use this when using your widgets:

    if (getWidgets().getWidget(parent).getChild(child) !=null)
    
    obviously this syntax didn't work for what I am trying to do. Not sure if I missed something. But using Widgets.getWidgetChild(id's) seems
    to have fixed this null error when the widget is not found.
    
    Link to comment
    Share on other sites

    • 2 weeks later...
    On 3/8/2021 at 8:29 PM, Deep Slayer said:

    Thanks for the help!

    Issue has been solved. I have been using this guide to use my widgets: 


    I think it may be out of date because in chapter 2, he explains to use this when using your widgets:

    
    if (getWidgets().getWidget(parent).getChild(child) !=null)
    
    obviously this syntax didn't work for what I am trying to do. Not sure if I missed something. But using Widgets.getWidgetChild(id's) seems
    to have fixed this null error when the widget is not found.
    

    Thanks, i had the same problem, life saver!

    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.