Jump to content

Widget help - wrong option being clicked


DGMonster

Recommended Posts

widgets.interact(219, 0, 1, "Continue");
sleep(random(2000,3000));

Instead of clicking on 219, 0, 1 sometimes it does click this but most of the time it gets stuck because it selects 219, 0, 2. Can anyone tell me what I'm doing wrong? Or show me the proper way to use widgets?

 

 

From the little code you provided, I must say I have absolutely no idea what you are trying to achieve. A more complex description of the context (what the script is supposed to do ingame) might help, but anyway in order to prevent any bugs you are supposed to make sure the widget you are interacting with is non-null, visible and has the required action and only then attempt to interact with it.

 

So if 219, 0, 1 are the ids of the widget you want to do

if (widgets.get(219, 0, 1) != null && widgets.get(219, 0, 1).isVisible() && widgets.get(219, 0, 1).hasAction("Continue"))
     widgets.get(219, 0, 1).interact("Continue");
Link to comment
Share on other sites

 

From the little code you provided, I must say I have absolutely no idea what you are trying to achieve. A more complex description of the context (what the script is supposed to do ingame) might help, but anyway in order to prevent any bugs you are supposed to make sure the widget you are interacting with is non-null, visible and has the required action and only then attempt to interact with it.

 

So if 219, 0, 1 are the ids of the widget you want to do

if (widgets.get(219, 0, 1) != null && widgets.get(219, 0, 1).isVisible() && widgets.get(219, 0, 1).hasAction("Continue"))
     widgets.get(219, 0, 1).interact("Continue");

 

Are you the guy that was told about race conditions like a few days ago? plus calling widgets.get(219, 0, 1) every time is uh, wasteful.

Link to comment
Share on other sites

It's not, if you actually understand how runescape works.

 

The fact that the script engine runs in a separate thread, and if you're constantly querying the client (in another thread mind you)for information in that manor, there will eventually be a race condition.

 

So there is, if you actually understood how java works.

 

Edit:and having the same method call everywhere is only not wasteful resource wise, it makes you look retarded.

Edited by matt123337
Link to comment
Share on other sites

The fact that the script engine runs in a separate thread, and if you're constantly querying the client (in another thread mind you)for information in that manor, there will eventually be a race condition.

 

So there is, if you actually understood how java works.

First of all I suggested how the code should work not how the final implementation of the class will look like. If you are new to programming, you will probably hear this quite often, you first create a functional program and then you optimise it. Would you prefer me to post a whole class instead of the condition to get the right widget and the interaction? 

 

Secondly, whether you stop getting the widget or not, you will still be checking those conditions. Take a look at our API and try to implement it in a script. Don't check the widget before interacting with it and you will get a wonderful NPE (Yes that happens even though the widget exists and you cached it). Be my guest and try it yourself, or don't and just start arguments about my code for no reason.

Link to comment
Share on other sites

Like people have said, we need some context, as the actual code OP posted isn't incorrect

 

 

From the little code you provided, I must say I have absolutely no idea what you are trying to achieve. A more complex description of the context (what the script is supposed to do ingame) might help, but anyway in order to prevent any bugs you are supposed to make sure the widget you are interacting with is non-null, visible and has the required action and only then attempt to interact with it.

 

So if 219, 0, 1 are the ids of the widget you want to do

if (widgets.get(219, 0, 1) != null && widgets.get(219, 0, 1).isVisible() && widgets.get(219, 0, 1).hasAction("Continue"))
     widgets.get(219, 0, 1).interact("Continue");

 

Widgets#interact has these checks built in

Link to comment
Share on other sites

Like people have said, we need some context, as the actual code OP posted isn't incorrect

 

 

Widgets#interact has these checks built in

I don't think it has the null checking though and I believe widgets are local entities so should be null checked when changing context. But yes maybe the isVisible() is not necessary but you don't generally want to interact with an invisible widget. At least I check when it is visible in order to interact with it. It all depends on what you are trying to achieve.

Link to comment
Share on other sites

I don't think it has the null checking though and I believe widgets are local entities so should be null checked when changing context. But yes maybe the isVisible() is not necessary but you don't generally want to interact with an invisible widget. At least I check when it is visible in order to interact with it. It all depends on what you are trying to achieve.

 

What do you mean by null checking when changing context?

 

Widgets#interact does have built in null & action check; that's the whole purpose of it being there. Aren't you confusing the Widgets API class with the RS2Widget Interactable class?

 

Link to comment
Share on other sites

What do you mean by null checking when changing context?

 

Widgets#interact does have built in null & action check; that's the whole purpose of it being there. Aren't you confusing the Widgets API class with the RS2Widget Interactable class?

 

When you cache a specific widget it's a RS2Widget (was meant for the guy quoting me above saying the conditions are "race" but better waste 0.00001% cpu than be sorry and freeze your client).  If your bot logs out and logs back in and try to interact with it you will get a NPE afaik. I don't know about Widgets.interact() as I never interacted with a widget via the Widgets class.

Link to comment
Share on other sites

If your bot logs out and logs back in and try to interact with it you will get a NPE afaik. I don't know about Widgets.interact() as I never interacted with a widget via the Widgets class.

 

Yeah, your object reference randomly turns into a fucking null if you get logged out.

Edited by demmonic
Link to comment
Share on other sites

 

No, you should never do that. You end up with a fucking mess of code you'd never be able to clean up.

 

ex:

if (state.getTextual() == "Interacting with Fountain") {
	return random(1300, 1900);
}

Yeh... let's just fuck all programming guidelines and go wild. 

 

Dude. Just do whatever the fuck you want. It is your program. Not my business. Stop quoting me every 10 minutes.

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...