DGMonster Posted January 17, 2016 Share Posted January 17, 2016 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? Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted January 17, 2016 Share Posted January 17, 2016 if you are handeling multiple chats ina row it could have still clicked "twice" in the previous window. Thus accidently clicking on the second widget Quote Link to comment Share on other sites More sharing options...
Token Posted January 17, 2016 Share Posted January 17, 2016 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"); Quote Link to comment Share on other sites More sharing options...
matt123337 Posted January 17, 2016 Share Posted January 17, 2016 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. Quote Link to comment Share on other sites More sharing options...
Token Posted January 17, 2016 Share Posted January 17, 2016 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. It's not, if you actually understand how runescape works. Quote Link to comment Share on other sites More sharing options...
matt123337 Posted January 17, 2016 Share Posted January 17, 2016 (edited) 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 January 17, 2016 by matt123337 Quote Link to comment Share on other sites More sharing options...
Token Posted January 17, 2016 Share Posted January 17, 2016 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. Quote Link to comment Share on other sites More sharing options...
FrostBug Posted January 17, 2016 Share Posted January 17, 2016 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 Quote Link to comment Share on other sites More sharing options...
Token Posted January 17, 2016 Share Posted January 17, 2016 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. Quote Link to comment Share on other sites More sharing options...
FrostBug Posted January 17, 2016 Share Posted January 17, 2016 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? Quote Link to comment Share on other sites More sharing options...
Token Posted January 17, 2016 Share Posted January 17, 2016 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. Quote Link to comment Share on other sites More sharing options...
matt123337 Posted January 17, 2016 Share Posted January 17, 2016 ...first create a functional program and then you optimise it... 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); } Quote Link to comment Share on other sites More sharing options...
demmonic Posted January 17, 2016 Share Posted January 17, 2016 (edited) 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 January 17, 2016 by demmonic Quote Link to comment Share on other sites More sharing options...
Token Posted January 17, 2016 Share Posted January 17, 2016 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. Quote Link to comment Share on other sites More sharing options...
demmonic Posted January 17, 2016 Share Posted January 17, 2016 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. Actually, that code he posted is from your shit jug filler on the SDN. Quote Link to comment Share on other sites More sharing options...