[SOLVED] Java Extension – If statement – getUtfString

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

MadHatDragon
Posts: 9
Joined: 09 Mar 2012, 09:47

[SOLVED] Java Extension – If statement – getUtfString

Postby MadHatDragon » 12 Mar 2012, 06:54

Code: Select all

    public void handleClientRequest(User sender, ISFSObject params)
    {
       String name = params.getUtfString("zoneSelected");
       ISFSObject response = new SFSObject();
        if(name == "zone1")
        {
           response.putUtfString("zonedata", "1,5,25");
        }
send("getGameZone", response, sender);
}


The code is above. The issue I cannot figure out is why the variable name does not equal “zone1” when in the trace for the server and on the client says that the name variable has “zone1” in it. It is successful in sending the information from the client to the server, the extension accepts it, but the if statement doesn’t activate, which means in theory they are not equal. How are they not equal when the trace for name is “zone1”? Do I need to convert the string from the ISFSObject if so how?

I have put traces in the if statement as well even though there are no traces in the code above. The trace does not activate and the SFSObject received has no data in it since the if statement did not activate.
Last edited by MadHatDragon on 12 Mar 2012, 15:23, edited 1 time in total.
Jake-GR
Posts: 59
Joined: 28 Dec 2011, 22:52

Re: Java Extension – If statement – getUtfString

Postby Jake-GR » 12 Mar 2012, 08:15

I had the same issue, and I think it has to do with the UtfString not actually being equal to a string or something like that.
The solution I used was to use the strings function equals(Object), I'm not at my dev system, so not positive if this is the fix.

Code: Select all

if (name.equals("zone1")
MadHatDragon
Posts: 9
Joined: 09 Mar 2012, 09:47

Re: Java Extension – If statement – getUtfString

Postby MadHatDragon » 12 Mar 2012, 15:22

That works! Thank you Jake again! It works exactly as expected now! That sure is tricky.
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: [SOLVED] Java Extension – If statement – getUtfString

Postby Bax » 13 Mar 2012, 15:24

When comparing strings you always have to use the .equals() method.
Paolo Bax
The SmartFoxServer Team

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 94 guests