Jump to content

In game message listener trouble


Recommended Posts

Posted (edited)

getBot().addMessageListener(f2pWc.this); 

@Override
    public void onMessage(Message message) {
        if (message.getType() == Message.MessageType.GAME && message.getMessage().contains("It's ready to add to the sapling.")) {
                 sapling.interact("Add-mulch");
        }
    }

It doesn't seem to be working.. :c

My bad everything seems to be a-okay! 

Edited by killsmh
Posted (edited)
42 minutes ago, killsmh said:

getBot().addMessageListener(f2pWc.this); 

@Override
    public void onMessage(Message message) {
        if (message.getType() == Message.MessageType.GAME && message.getMessage().contains("It's ready to add to the sapling.")) {
                 sapling.interact("Add-mulch");
        }
    }

It doesn't seem to be working.. :c


No need to do addMessageListener if it's you main class extending from Script :) 

Just add some debug logs to check what codes gets executed and which not.
I'm not sure where the sapling variable is coming from, I asusme you set it in the onLoop? Just load the sapling ad hoc

BUT those are bad habbits, do this instead:
Never use any interaction code in the messageListener, only in the onLoop thread.
You can set a boolean in the onMessage and check that boolean in the onLoop to execute your code and reste the boolean after that :)

Edited by Khaleesi
  • Heart 1
Posted
On 7/13/2023 at 11:21 PM, Khaleesi said:


No need to do addMessageListener if it's you main class extending from Script :) 

Just add some debug logs to check what codes gets executed and which not.
I'm not sure where the sapling variable is coming from, I asusme you set it in the onLoop? Just load the sapling ad hoc

BUT those are bad habbits, do this instead:
Never use any interaction code in the messageListener, only in the onLoop thread.
You can set a boolean in the onMessage and check that boolean in the onLoop to execute your code and reste the boolean after that :)

Thank you for helping everyone!

  • Like 1

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...