Jump to content

Replace(Char, char) error


Lol_marcus

Recommended Posts

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();
        }
    }

 

Link to comment
Share on other sites

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

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();
        }
    }

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

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

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