Jump to content

Game log listener


Recommended Posts

Posted (edited)

You need to get a message listener, the method is onMessage() if I recall correctly.

 

EDIT:

 

I.e

   private void onMessage(String message) {
    	if(message.contains("You get some oak logs.")) {
    		itemsMade ++;
    	}
    }

You can make specific message type listeners too:

if you put that in the onMessage method


if(getType().equals(Message.MessageType.GAME)) {
 // game message
}

if(getType().equals(Message.MessageType.PLAYER)) {
 // player message
}

and in the onStart() method:

getBot().addMessageListener(this);
Edited by Vilius
Posted (edited)

Hi, I have been searching round the API but can't seems to find a listener I could implement that gets executed when a game event (like A magical force stops you from moving) appears on the game log. Or is there some other way of reading these?

 

 

You need to get a message listener, the method is onMessage() if I recall correctly.

   private void onMessage(String message) {
    	if(message.contains("You get some oak logs.")) {
    		itemsMade ++;
    	}
    }

 

You can do this, but this example is incorrect, the argument is not a String. It should be:

@Override
public void onMessage(Message message){

    if(e.getType() == Message.MessageType.GAME &&
       e.getMessage().equals("A magical force stops you from moving")){

           // do something
    }
}
Edited by Explv
  • Like 1
Posted

 

You can do this, but this example is incorrect, the argument is not a String. It should be:

@Override
public void onMessage(Message message){

    if(e.getType() == Message.MessageType.GAME &&
       e.getMessage().equals("A magical force stops you from moving")){

           // do something
    }
}

Ah yes, been some time when I used message listeners :x

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