Jump to content

Need help with widget interact action filer


Recommended Posts

Posted

Hi everyone.

Currently I'm working on a script that buys items needed. Unfortunatly , I ran in to a problem.

When buying the item, I want it to press the +5% button in the buy screen. To do this I need to filter out this button. Since I'm not willing to use ID's, I tried filtering on interact actions. This is the code I used:

RS2Widget plusButton = getWidgets().singleFilter(getWidgets().getAll(), w -> w.getInteractActions()[0].equals("+5%"));
plusButton.interact();

When I run this code, the OSBot logger returns the following error:

[ERROR][Bot #1][03/23 05:07:58 PM]: Error in script executor!
java.lang.NullPointerException
    at PlainPizzaMaker.buyItem(PlainPizzaMaker.java:130)
    at PlainPizzaMaker.onLoop(PlainPizzaMaker.java:116)
    at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(nj:193)
    at java.lang.Thread.run(Unknown Source)

Any suggestions on how to fix it and why it's not working?

Posted

Theres a couple of null checks that need to happen for that to effectively work. 

Inside the lambda, w needs to be null checked. Also, w.getInteractActions() can return null if the widget does not have any interact actions, so that needs to be null checked.

Finally, plusButton itself can be null. Null check that before interacting with it.

You should also check if the array contains the string rather than just checking the first index

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...