Jump to content

Proper use of RS2Widgets isVisible()?


mrzoro35

Recommended Posts

So basically, I am trying to make a stupid simple bot that buys one item from a shop. Nothing really complex or anything. I am having trouble with it opening the shop, buying the item and then closing it. There is no .isOpen() method for widgets (obviously), but .isVisible() seems like it should be the widget equivalent.

 

Basically I'm either getting a NPE, or it will open the shop, buy 10, then close the window, re-open, buy, close... until the inventory is full, it will bank and then repeat.

 

 

So my first guess was to do something along the lines of:

 

Objects created (both defined at the beginning of case "BUY"):

NPC npc = getNpcs().closest(502);
RS2Widget shop = widgets.get(300, 2, 29);

Actions:

			if (!shop.isVisible()) {
				if (npc != null) {
					log("npc is not null");
					npc.interact("Trade");
					log("Opening shop");
				}
			} else {
				if (shop != null) {
					log("Shop is not null");
					if (shop.getItemAmount() > 0) {
						log("The store has some items you can buy!");
						shop.interact("Buy 10");
					}
				}
			}

(the logs were put in pretty much every step for troubleshooting)

 

 

When I tried this, it gave me a NPE.

 

 

So then I tried creating object "npc" directly before the first half of the code, creating object "shop" directly before the second half, and beginning the second half with the isVisible() if statement.

 

Something like this:

			NPC npc = getNpcs().closest(502);
				if (npc != null) {
					log("npc is not null");
					npc.interact("Trade");
					log("Opening shop");
				}
                        RS2Widget shop = widgets.get(300, 2, 29);
                            if (shop.isVisible()) {
				  if (shop != null) {
				     log("Shop is not null");
					if (shop.getItemAmount() > 0) {
						log("The store has some items you can buy!");
						shop.interact("Buy 10");
					}
				}
			}

Which got rid of the NPE but then was doing that weird thing where it would open the shop, buy, close the shop just to reopen it thing.

 

 

I've tried putting the code out of order by putting shop.isVisible() rather than !shop.isVisible() in the beginning of the case and then starting with the buying process rather than opening the store first.... NPE.

 

I've also tried null checking before the isVisible(), but then the script skips the rest of the code and loops just that point where it switches states to the "BUY" case.

 

I even went ahead and tried "shop.isVisible() == false" just for shits and giggles and that obviously didn't work either

 

 

Obviously I'm doing something wrong. And it is probably stupid. I'm new, I have minimal prior knowledge but I did just order a java book and will be continuing to teach myself and learn about the programming language itself.. But for right now, i'm going to ask this very nooby question :P.

 

Also on a side note, I've never really understood how do you get the interact method to not try to do the same action 5 times all at once without just doing a simple sleep? I see a lot of new scripters kind of get roasted for that and I guess I just don't know enough yet to know how to do it "properly". Where should I start in that respect?

 

 

Thank you in advanced for the help!

 

 

  • Like 1
Link to comment
Share on other sites

You cant check if a widget object is visible unless you null check first.

I would try getwidgets#isvisible(int int) just to check if it exists and visible.

For the repeating actions, take a look and redo tour script logic.

Look into conditionsleep also.

 

Thank you for the quick response. I will make some changes and let you know. Appreciate it!

  • Like 1
Link to comment
Share on other sites

Not a problem. Just post again in the section and I will help when I can.

 

 

you can check if the shop is open

 

getShop.isOpen();

I was actually just about to reply and say that I overlooked the "getStore()" method, and that i added that and now it works and doesn't close after every time it buys. Now I just have to make tweaks here and there to make it run smoother and more human-like. Thank you guys so much for the help biggrin.png

Edited by mrzoro35
  • Like 3
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...