Deep Slayer 20 Share Posted March 7, 2021 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 More sharing options...
RetroBot 35 Share Posted March 7, 2021 WidgetChild example = Widgets.getWidgetChild(1, 1); if (example != null && example.isVisible()) { //do stuff } else { // open window } Link to comment Share on other sites More sharing options...
Deep Slayer 20 Author Share Posted March 7, 2021 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 More sharing options...
Deep Slayer 20 Author Share Posted March 7, 2021 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 More sharing options...
AsBakedAsCake 202 Share Posted March 7, 2021 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 More sharing options...
Pseudo 179 Share Posted March 7, 2021 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 More sharing options...
Deep Slayer 20 Author Share Posted March 9, 2021 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 More sharing options...
Libra12 2 Share Posted March 22, 2021 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.