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.

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


×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock