Jump to content

Replace(Char, char) error


Recommended Posts

Posted

I got the error "The method replace(char char) is undefined for the type Player". How should I go about removing the space from the name? :( 

Inb4 super easy fix and I feel like a complete noob. ^^

	public void sendRequest() throws InterruptedException	{

		Player Name = getPlayers().closest("Example Name");
		Name = Name.replace(' ', '_');
		
    if (Name != null && Name.isVisible()) {
    	Name.interact("Trade with");
    	sleep(random(2000, 3000));
    	new ConditionalSleep(5000, 500) {
                @Override
                public boolean condition() throws InterruptedException {
                    return getTrade().isCurrentlyTrading();
                }
            }.sleep();
        }
    }

 

Posted
1 minute ago, Lol_marcus said:

Still getting the same error. :( 

Just realized what youre trying to do

        Player Name = getPlayers().closest("Example Name");
        Name = Name.replace(' ', '_');

Name is a Player instance. Youre trying to call a String function

        Player player = getPlayers().closest("Example Name");
        String name = player.getName().replace(' ', '_');

also forget what I said above, single quotes work fine

  • Like 1
Posted
1 hour ago, Camaro said:

Just realized what youre trying to do

        Player Name = getPlayers().closest("Example Name");
        Name = Name.replace(' ', '_');

Name is a Player instance. Youre trying to call a String function

        Player player = getPlayers().closest("Example Name");
        String name = player.getName().replace(' ', '_');

also forget what I said above, single quotes work fine

I've tried that now, and I'm getting a different error. 

"The method interact(String) is undefined for the type String"

It has something to do with name.interact, because if I change that to "player.interact", it doesn't give an error, but it doesn't trade my player. :???:

	public void sendRequest() throws InterruptedException	{

		Player player = getPlayers().closest("Example Name");
		String name = player.getName().replace(' ', '_');
		
    if (name != null && player.isVisible()) {
    	name.interact("Trade with");
    	sleep(random(2000, 3000));
    	new ConditionalSleep(5000, 500) {
                @Override
                public boolean condition() throws InterruptedException {
                    return getTrade().isCurrentlyTrading();
                }
            }.sleep();
        }
    }

 

Posted
6 minutes ago, Lol_marcus said:

I've tried that now, and I'm getting a different error. 

"The method interact(String) is undefined for the type String"

It has something to do with name.interact, because if I change that to "player.interact", it doesn't give an error, but it doesn't trade my player. :???:


	public void sendRequest() throws InterruptedException	{

		Player player = getPlayers().closest("Example Name");
		String name = player.getName().replace(' ', '_');
		
    if (name != null && player.isVisible()) {
    	name.interact("Trade with");
    	sleep(random(2000, 3000));
    	new ConditionalSleep(5000, 500) {
                @Override
                public boolean condition() throws InterruptedException {
                    return getTrade().isCurrentlyTrading();
                }
            }.sleep();
        }
    }

 

Why do you need to take the spaces out in the first place?

Posted (edited)
11 minutes ago, Lol_marcus said:

I read on another posts that if you have a space in your name you have to remove it, otherwise the bot won't recognize your name/won't trade you. :/

Not sure exactly how that works, but this might

Player p = getPlayers().singleFilter(p -> p != null && p.getName().replace(" ", "").equals("namewithoutspaces"))

Edited by Camaro
Posted
45 minutes ago, Lol_marcus said:

I've tried that now, and I'm getting a different error. 

"The method interact(String) is undefined for the type String"

It has something to do with name.interact, because if I change that to "player.interact", it doesn't give an error, but it doesn't trade my player. :???:


	public void sendRequest() throws InterruptedException	{

		Player player = getPlayers().closest("Example Name");
		String name = player.getName().replace(' ', '_');
		
    if (name != null && player.isVisible()) {
    	name.interact("Trade with");
    	sleep(random(2000, 3000));
    	new ConditionalSleep(5000, 500) {
                @Override
                public boolean condition() throws InterruptedException {
                    return getTrade().isCurrentlyTrading();
                }
            }.sleep();
        }
    }

 

"The method interact(String) is undefined for the type String"
Read your logic. name is now type of String 
It is not type of Player anymore. You now need to do player.interact("trade with") or whatever

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