Jump to content
Sign in to follow this  
Sophisticated

Having a problem using interfaces.

Recommended Posts

Hi guys, I decided to rewrite my simple herblore script. I'm using the node framework now and the code is a little bit better. But once again I get problems when I'm trying to see if the interface I'm using is up or not.

This is the method that gives me problems:

	// Get's the interface.
	private void getInterface()
	{
		RSInterface target = Interfaces.get(309, 3);
		if (Timing.waitCondition(new Condition()
		{
			@Override
			public boolean active()
			{
				General.sleep(50, 150);
				return target != null && !target.isHidden();
			}
		}, General.random(2500, 3500)))
		{
			General.println("Calling chooseMakeOption!");
			chooseMakeOption(target);
		}
		else
		{
			General.println("We are running getInterface() again.");
			getInterface();
		}
	}

After I use a guam leaf and a vial of water on each other, I call this method. But everytime this method calls itselfs again and after the second call the script continues to work and chooseMakeOption get's called. I've tried different things but I can't seem to properly fix this. Is there someone able to help me out?

Here is the full class if you're wondering:  https://pastebin.com/Wdv3sAgw

Share this post


Link to post
Share on other sites

When you originally call getInterface(), the target interface is equal to null as it isn't shown. This null value gets passed into active() and just loops until the time runs out. The if statement then returns false, which makes your else statement activate which then calls getInterface() again. This time target is not equal to null, so it returns true and calls chooseMakeOption().

The solution to this is to create the interface within the active().

@Override
public boolean active() {
General.sleep(50, 150);
RSInterface target = Interfaces.get(309, 3);
return target != null && !target.isHidden();
}

Edited by fegmo

Share this post


Link to post
Share on other sites

If I were you I would get rid of that whole method and just get an instance of the interface when you actually use the interface, theres no real need to add a wait condition in after the interface object too. Use a wait condition directly after you perform an action (such as using the herblore items on one another)

Share this post


Link to post
Share on other sites
2 minutes ago, Naton said:

If I were you I would get rid of that whole method and just get an instance of the interface when you actually use the interface, theres no real need to add a wait condition in after the interface object too. Use a wait condition directly after you perform an action (such as using the herblore items on one another)

I'd get rid of and change alot more than just that whole method.

  • Haha 1

Share this post


Link to post
Share on other sites
10 hours ago, Sophisticated said:

 

	// Get's the interface.
	private void getInterface()
	{
		RSInterface target = Interfaces.get(309, 3);
		if (Timing.waitCondition(new Condition()
		{
			@Override
			public boolean active()
			{
				General.sleep(50, 150);
				return target != null && !target.isHidden();
			}
		}, General.random(2500, 3500)))
		{
			General.println("Calling chooseMakeOption!");
			chooseMakeOption(target);
		}
		else
		{
			General.println("We are running getInterface() again.");
			getInterface();
		}
	}

 

 

 

if (clicked on herb & vial)

            Dynamic sleep until

            Interfaces.isInterfaceValid( interface's index);

 

Problem solved.

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, Einstein said:

 

 

if (clicked on herb & vial)

            Dynamic sleep until

            Interfaces.isInterfaceValid( interface's index);

 

Problem solved.

Thanks for the reply, I tried adding your line of code.  After adding a null check everything seemed alright, because if I don't add a nullcheck, I get a NPE error often. But then I noticed whenever target == null, the target will stay null until I call getInterface() another time.

This is how the method looks right now:

	// Get's the interface.
	private void getInterface()
	{
		RSInterface target = Interfaces.get(309, 3);
		if (Timing.waitCondition(new Condition()
		{
			@Override
			public boolean active()
			{
				General.sleep(50, 150);
				if (target != null)
				{
					return Interfaces.isInterfaceValid(309);
				}
				General.println("Returning false, interface = null!");
				return false;
			}
		}, General.random(2500, 3500)))
		{
			General.println("Calling chooseMakeOption!");
			chooseMakeOption(target);
		}
		else
		{
			General.println("We are running getInterface() again.");
			getInterface();
		}
	}

The bandaid fix that works is adding a long sleep before calling getInterface(). But I'd prefer to have a better fix for this. Do you have any idea why target keeps being null even when I've first clicked on both items and the interface is up (atleast on my screen)?

Share this post


Link to post
Share on other sites
1 minute ago, Sophisticated said:

Thanks for the reply, I tried adding your line of code.  After adding a null check everything seemed alright, because if I don't add a nullcheck, I get a NPE error often. But then I noticed whenever target == null, the target will stay null until I call getInterface() another time.

This is how the method looks right now:

 

 

You didn't solve the problem at all.

The variable target is assigned the value returned by Interfaces.get(309, 3), and this expression will always return null because you call the method right after the script clicks the two items, and the interface is simply not available yet.

And then, in the conditional sleep, you take target (which equals null) and you are repeatedly checking if its null value has magically changed to !null.

I've commented your code in an attempt to make matters more clearly:

 

// Please delete this.
	private void getInterface() // if this method is called right after you clicked the two herblore items
	{
		RSInterface target = Interfaces.get(309, 3); // target will be set equal to null
		
      
      if (Timing.waitCondition(new Condition() // and with target = null,
                                              //  you start looping for a few seconds, constantly checking if something changed:
		{
			@Override
			public boolean active()
			{ 
				General.sleep(50, 150);
				if (target != null)  // target will always be null;
				{
					return Interfaces.isInterfaceValid(309); // this statement will never execute
				}
				General.println("Returning false, interface = null!");
				return false;
			}
		}, General.random(2500, 3500)))
		{
			General.println("Calling chooseMakeOption!");
			chooseMakeOption(target);
		}
		else
		{
			General.println("We are running getInterface() again.");
			getInterface();
		}
	}

 

I suggest you delete this method entirely, and write a new one using this pseudo code as a guideline:

if (clicked on herb & vial)
     newAndBetterMethod();


// this is your new method
void newAndBetterMethod() {
    Timing.waitCondition( Conditon that returns Interfaces.isInterfaceValid(index ), 3000 );
}
  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, Einstein said:

 

 

You didn't solve the problem at all.

The variable target is assigned the value returned by Interfaces.get(309, 3), and this expression will always return null because you call the method right after the script clicks the two items, and the interface is simply not available yet.

And then, in the conditional sleep, you take target (which equals null) and you are repeatedly checking if its null value has magically changed to !null.

I've commented your code in an attempt to make matters more clearly:

 

// Please delete this.
	private void getInterface() // if this method is called right after you clicked the two herblore items
	{
		RSInterface target = Interfaces.get(309, 3); // target will be set equal to null
		
      
      if (Timing.waitCondition(new Condition() // and with target = null,
                                              //  you start looping for a few seconds, constantly checking if something changed:
		{
			@Override
			public boolean active()
			{ 
				General.sleep(50, 150);
				if (target != null)  // target will always be null;
				{
					return Interfaces.isInterfaceValid(309); // this statement will never execute
				}
				General.println("Returning false, interface = null!");
				return false;
			}
		}, General.random(2500, 3500)))
		{
			General.println("Calling chooseMakeOption!");
			chooseMakeOption(target);
		}
		else
		{
			General.println("We are running getInterface() again.");
			getInterface();
		}
	}

 

I suggest you delete this method entirely, and write a new one using this pseudo code as a guideline:

if (clicked on herb & vial)
     newAndBetterMethod();


// this is your new method
void newAndBetterMethod() {
    Timing.waitCondition( Conditon that returns Interfaces.isInterfaceValid(index ), 3000 );
}

Oh now I see what I did wrong. I've changed a little bit of the method. And it now works perfectly fine. Thank you very much!

Here is what I did:

	// Get's the interface.
	private void getInterface()
	{
		if (Timing.waitCondition(new Condition()
		{
			@Override
			public boolean active()
			{
				General.sleep(50, 150);

				General.println("We zitten in getinterface2");
				return Interfaces.isInterfaceValid(309);
			}
		}, General.random(2500, 3500)))
		{
			RSInterface target = Interfaces.get(309, 3);
			General.println("Calling chooseMakeOption!");
			chooseMakeOption(target);
		}
		else
		{
			General.println("We are running getInterface() again.");
			getInterface();
		}
	}

 

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×