Jump to content
fredrico123

String comparison problem

Recommended Posts

I am writing a function that checks if a specific player is on my friendslist, and not sure what I am missing in here...

public boolean isFriend(String name) {
        RS2Widget widget = script.widgets.get(429, 9);
        if (widget == null)
            return false;

        for (RS2Widget friend : widget.getChildWidgets()) {
            if (friend.getMessage().equals(name)) {
                return true;
            }
        }

        return false;
    }

The following code works pretty well if the name is not separated.

Example of a working check: abc123 -> If is on the list, returns true, otherwise, returns false

Example of a non-working check: the king -> this will keep returning false whether or not the player is on my friend list

 

Thanks in advance!

Edited by fredrico123
Link to comment
Share on other sites

23 minutes ago, fredrico123 said:

I am writing a function that checks if a specific player is on my friendslist, and not sure what I am missing in here...


public boolean isFriend(String name) {
        RS2Widget widget = script.widgets.get(429, 9);
        if (widget == null)
            return false;

        for (RS2Widget friend : widget.getChildWidgets()) {
            if (friend.getMessage().equals(name)) {
                return true;
            }
        }

        return false;
    }

The following code works pretty well if the name is not separated.

Example of a working check: abc123 -> If is on the list, returns true, otherwise, returns false

Example of a non-working check: the king -> this will keep returning false whether or not the player is on my friend list

 

Thanks in advance!


The player names in the widgets probably have non-breaking spaces instead of regular spaces:
 

if (friend.getMessage().replace('\u00A0', ' ').equals(name))


Or at the top of your function:

name = name.replace(' ', '\u00A0');

 

Edited by Explv
  • Like 2
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.

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