Page 1 of 1

if and else

Posted: Sun Mar 27, 2011 6:44 pm
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?

Re: if and else

Posted: Sun Mar 27, 2011 7:08 pm
by hope
if (activeChar.isGM())
because of this line only gms will see it

Re: if and else

Posted: Sun Mar 27, 2011 7:10 pm
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?

Re: if and else

Posted: Mon Mar 28, 2011 9:58 am
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);
?