Jump to content

interact() weird behavior


Tylersbored

Recommended Posts

So I am coming across a weird problem in my scripting adventure. The current script that I am trying to make is a Jug filler and for some reason, code that uses "interact()" sometimes does the action twice. Here is an example:

fiW2FFb.png

I thought the conditional sleep would make it stop but it still does the double action of "Trade with" sometimes, not all the time. 

Another example:

UBd8y1D.png

This is my run method for my jug filling task. It will select a jug and then select the fountain to fill the jugs. My problem with this section is that my bot will select the jug while it is already filling other jugs and then use it on the fountain again. This only happens like half the time, sometimes the bot will fill the jugs perfectly. Maybe isAnimating() does not catch the filling animation? that is a possibility because when I was debugging and looking at the animation ids, the bot would switch in between the filling animation id and -1 so maybe it depends on if the check gets lucky or not. But I checked the documentation of isAnimating() and it said that even if the bot is doing a series of animations, it should still return true. I am a bit lost lols.

If you guys have a better way of doing what I am doing please help a fellow scripter out :D Thanks guys!

 

Link to comment
Share on other sites

I'm not exactly sure what "this" refers to in your first snippet so I can't help you with that but when you call interact() on anything, an InteractionEvent instance is created with a default threshold of 5 attempts so it may execute the same action up to 5 times and it's equivalent to

InteractionEvent e = new InteractionEvent(someEntity, someAction);
e.setCameraDistance(14);
e.setHover(false);
e.setMaximumAttempts(5);
e.setOperateCamera(true);
script.execute(e);

In java we use the equals() method to compare 2 non-primitives like String instances so your condition should be 

@Override
public boolean condition() throws InterruptedException {
	return script.inventory.getItemInSlot(27).getName().equals("Jug of water");
}

But you should take into consideration this will throw a NullPointerException if there is no item in that slot, eg when you don't have 28 jugs left and you only go to fountain with 20, so maybe this may work better

@Override
public boolean condition() {
	return !script.inventory.contains("Jug");
}

Also void using any animations as they are not continuous and therefore not reliable (there is a short transition time between animations when the method returns false)

  • Like 5
Link to comment
Share on other sites

@Tylersbored

Like Token said, you should be using .equals() to compare the String values for equality, not ==. 

For primitives such as int, boolean etc. you use ==

For non-primitives such as String, Integer you use . equals() because == will only return true if the object references are the same, whereas equals() will compare the values

 

Link to comment
Share on other sites

8 hours ago, Token said:

I'm not exactly sure what "this" refers to in your first snippet so I can't help you with that but when you call interact() on anything, an InteractionEvent instance is created with a default threshold of 5 attempts so it may execute the same action up to 5 times and it's equivalent to


InteractionEvent e = new InteractionEvent(someEntity, someAction);
e.setCameraDistance(14);
e.setHover(false);
e.setMaximumAttempts(5);
e.setOperateCamera(true);
script.execute(e);

In java we use the equals() method to compare 2 non-primitives like String instances so your condition should be 


@Override
public boolean condition() throws InterruptedException {
	return script.inventory.getItemInSlot(27).getName().equals("Jug of water");
}

But you should take into consideration this will throw a NullPointerException if there is no item in that slot, eg when you don't have 28 jugs left and you only go to fountain with 20, so maybe this may work better


@Override
public boolean condition() {
	return !script.inventory.contains("Jug");
}

Also void using any animations as they are not continuous and therefore not reliable (there is a short transition time between animations when the method returns false)

very helpful post. Thank you man, you've been helping me alot

4 hours ago, Explv said:

@Tylersbored

Like Token said, you should be using .equals() to compare the String values for equality, not ==. 

For primitives such as int, boolean etc. you use ==

For non-primitives such as String, Integer you use . equals() because == will only return true if the object references are the same, whereas equals() will compare the values

 

yeah haha thanks for the advice. I learned that in my java programming course but for some reason it went over my head xD

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