if and else

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
Helix
Posts: 34
Joined: Sun Apr 25, 2010 6:33 pm

if and else

Post by Helix »

L2J Revision Number: newest
L2JDP Revision Number: newest


Hello,

i am very new at developing own sourcecodes for l2j cores and i got now my first question. Why does my script not work?

i added in Enterworld.java the following lines:

Code: Select all

         if (activeChar.isGM())            {                    activeChar.sendMessage("Hallo GM!");            }        else        {            activeChar.sendMessage("Hallo Spieler");        } 
if i log in as a gm char there is a "Hallo GM!" in the System Window. But for normal players there doesnt happen anything...why?
hope
Posts: 1160
Joined: Thu Aug 30, 2007 5:17 pm

Re: if and else

Post by hope »

if (activeChar.isGM())
because of this line only gms will see it
Helix
Posts: 34
Joined: Sun Apr 25, 2010 6:33 pm

Re: if and else

Post by Helix »

ah okay i got it now working with these lines:

Code: Select all

         if (activeChar.isGM())                    {                    activeChar.sendMessage("Hallo GM!");            }        else if (!activeChar.isGM())        {            activeChar.sendMessage("Hallo") ;        } 
can anyone explain to me how i can set a variable with the "HalloGM!" text and how to use it?
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: if and else

Post by jurchiks »

The first code should work perfectly code-wise... there's no need to check the gm status twice for that.
About the second - do you mean smth like:

Code: Select all

String helloMsg1 = "Hallo GM!";String helloMsg2 = "Hallo Spieler!";if (activeChar.isGM())    activeChar.sendMessage(helloMsg1);else    activeChar.sendMessage(helloMsg2);
?
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Post Reply