Jump to content

Game log listener


Tazmania

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

 

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

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