Jump to content

Need help with widget interact action filer


gerwinb500

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

On 3/23/2020 at 2:55 PM, gerwinb500 said:

I think understand what you mean, but I don't know how to implement the nul check of w and w.getInteractActions(). Could you maybe write a sample code or explain? 

learn java pls

 

There are easier methods to use btw https://osbot.org/api/org/osbot/rs07/api/Widgets.html

Edited by Chris
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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