Jump to content
  • 0

[Help] enterworld if statement


Question

Posted

When I'm checking character username when character enters the world if statement don't work even if it should. For e.g.

if (activeChar.getName() == "Admin") { activeChar.sendMessage("Hello Admin");}

,this part of code is placed in enterworld.java, it is L2jserver H5. Btw when i just using

activeChar.sendMessage(activeChar.getName);

it works...

4 answers to this question

Recommended Posts

  • 0
Posted

It's getName()

Plus it is a common mistake to compare strings using == operator. Don't do that! Here's an example:

String a = new String ("a");
String b = new String ("a");
System.out.println (a == b);

Will return false. "Why?" you ask? That's your homework for tonight ;)

  • 0
Posted

When I'm checking character username when character enters the world if statement don't work even if it should. For e.g.

if (activeChar.getName == "Admin") { activeChar.sendMessage("Hello Admin")}

,this part of code is placed in enterworld.java, it is L2jserver H5. Btw when i just using

activeChar.sendMessage(activeChar.getName);

it works...

 

Character username? If you mean the account ID, That wouldn't work....

but if you just want to check the name, then this Would work, as mogo said. also you might need to put ; in the end, before the } symbol.

  • 0
Posted

Sorry mistake in post, there are brackets and ; in my code,no errors in eclipse,yes i'm checking for character name. Thanks mongo, as i was expecting the problem is equal operator.

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
Answer this question...

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

×
×
  • Create New...