Author Topic: If statement not working?  (Read 1234 times)

Quote
package WordTest
{
   function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
   {
      parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%fmsg);
      if(%name $= $Pref::Player::Netname && %msg $= "Hi There")
      {
         %wordvar = getWord(%msg, 4);
         commandToServer('messagesent',"[RedBot]: This " @ %wordvar);
      }
      else
      {
         commandToServer('messagesent',"dumb");   
      }
   }
};
activatePackage(WordTest);

Now this is supposed to check and see if my name is my playername, and if my message is Hi there.
When I type Hi There it will display both "[RedBot]: This"  And "dumb"

What am I doing wrong, because first, my RedBot line isn't display the %wordvar variable, AND my if statement is applying both my initial if, and the else.

Quote
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
   {
      parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%fmsg);

possible problem

Tried changing, no solution.

So apparently after I type "Hi there" if anyone at all types a chat message it will send both "[RedBot]: This"  and "dumb"
I have no idea

Did you code this and then make changes and exec it a bunch of times without restarting?
Sometimes packages can get messed up when you do that, so if you did, try restarting BL then trying it.

Did you code this and then make changes and exec it a bunch of times without restarting?
Sometimes packages can get messed up when you do that, so if you did, try restarting BL then trying it.
Tried, I don't use exec, I always restart.

So, any other ideas?

Tried, I don't use exec, I always restart.
.... owch. the time wasted doing this must be immense.
So, any other ideas?
did you try mine

.... owch. the time wasted doing this must be immense.
did you try mine

It is, but I try to get my stuff right before I run it so.

And yes I renamed the %fmsg at the end to %msg, no change at all

Try this:

Code: [Select]
package WordTest
{
function clientcmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
{
Parent::clientcmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
    switch$(%msg)
    {
         case "Hi there":
         if(%name $= $Pref::Player::NetName)
         {
              %wordvar = getWord(%msg, 4);
                       commandToServer('messagesent',"[RedBot]: This " @ %wordvar);
         }
                  else
                  {
                       commandToServer('messagesent',"dumb");  
                  }
    }
}
};
activatePackage(WordTest);
Or you could try replacing $Pref::Player::NetName with your name.

Code: [Select]
package WordTest
{
   function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
   {
      parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
      echo($Pref::Player::Netname SPC %name SPC %msg);
      if(%name $= $Pref::Player::Netname && %msg $= "Hi There")
      {
         %wordvar = getWord(%msg, 4);
         commandToServer('messagesent',"[RedBot]: This " @ %wordvar);
      }
      else
      {
         commandToServer('messagesent',"dumb");  
      }
   }
};
activatePackage(WordTest);
Try that echo. Then monitor the console to make sure everything's what it should be.

Warning - while you were typing a new reply has been posted. You may wish to review your post.
ffff

Why would you do that?
If he wants to have more than one message to reply too, he's going to be checking the name in every case, spamming up the code with copies of the same thing
Check the case, then do a switch

Does noone notice the lack of sense?
If %msg is "Hi There", getWord(%msg, 4) will always return "".

Does noone notice the lack of sense?
If %msg is "Hi There", getWord(%msg, 4) will always return "".
Can you explain further please?

Also with the echo it did echo
Code: [Select]
JazZ JazZ Hi there Exactly that was in console

Can you explain further please?
"Hi there" is only two words long, but you're attempting to get the fourth (fifth the way humans count) word

"Hi there" is only two words long, but you're attempting to get the fourth (fifth the way humans count) word

okayy, hold on, so the number itself is not how many characters forward, but words?

okayy, hold on, so the number itself is not how many characters forward, but words?
Yes
And it will only return one word of the text