Jump to content

reading text from chat box


Recommended Posts

Posted
10 minutes ago, d0zza said:

What are you using to search the chatbox?

You can use OnMessage to do something whenever the message you want has appeared in the chatbox.

Thanks for your reply.

Would that method overwrite work for searching substrings with spaces?

I am using

getChatbox().contains()
Posted
15 minutes ago, Thanfor said:

Thanks for your reply.

Would that method overwrite work for searching substrings with spaces?

I am using


getChatbox().contains()

contains method in Chatbox checks for MessegeType instances

You want to use the message listener and then do a contains method that checks for sub strings equaling "has happened". You may encounter issues (depending on the method) with, exact phrases though. ("has happened" vs  "has happened.")

Posted
23 minutes ago, Thanfor said:

Thanks for your reply.

Would that method overwrite work for searching substrings with spaces?

I am using


getChatbox().contains()

Spaces don't need any work for the chatbox, only for player names.

Like dreameo said, use the message listener that is part of the osbot api.

Posted (edited)

Here is how you would go about doing this.

If a player (anyone) types "noob" or "nub" your bot will then reply "im not a noob you are!".

    public void onMessage(Message message) throws java.lang.InterruptedException {
	if(message.getType() == Message.MessageType.PLAYER) {
			if (message.getMessage().contains("noob") || message.getMessage().contains("nub")) {
				getKeyboard().typeString("im not a noob you are!");
			}
		}
    }

 

Edited by DeadPk3r
Posted

And if you want to get recent messages from the chatbox after a while, here is what you will want to do.

You add this to your class

implements MessageListener

and this is the code

getChatbox().getMessages(MessageType.PLAYER).get(0).contains("noob")

Gets the last player message sent containing noob. I find it useful because I have a message tracking system inside my script.

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