mIRC Home    About    Download    Register    News    Help

Print Thread
#165056 21/11/06 07:09 PM
K
kaosAD
kaosAD
K
I try to do the following:

if $len(%pos = $pos(%msg, mother)) != 0 {
/echo someone says mother at %pos
} else if $len(%pos = $pos(%msg, father)) != 0 {
/echo someone says father at %pos
}

But the script does not seem to work. I think because I am assigning a value to %pos and at the same time sending the value over to the function $len(). How do I rectify this?

Last edited by kaosAD; 21/11/06 07:13 PM.
#165057 21/11/06 07:23 PM
Joined: Apr 2004
Posts: 755
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 755
Great feature in PHP doesnt work in mIRC youll need to split it over multiple lines something like:
Code:
var %pos = $pos(%msg, mother)
if (%pos) { 
  dosomethinghere
}
else ...

#165058 21/11/06 07:43 PM
K
kaosAD
kaosAD
K
That means if I have multiple comparisons for example the following

var %pos = $pos(%msg, mother);
if (%pos) {
/echo someone says mother at %pos
} else {
%pos = $pos(%msg, father)
if (%pos) {
/echo someone says father at %pos
} else {
%pos = $pos(%msg, brother)
if (%pos) {
/echo someone says brother at %pos
} else {
%pos = $pos(%msg, sister)
if (%pos) {
/echo someone says sister at %pos
}
}
}
}

with deeper and deeper indentation. This is horrendous frown
Can you suggest a better way of writing it?

#165059 21/11/06 07:59 PM
Joined: Dec 2002
Posts: 2,884
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,884
Code:
if ($pos(%msg, mother, 1)) echo someone says mother at $v1
elseif ($pos(%msg, father, 1)) echo someone says father at $v1
elseif ($pos(%msg, brother, 1)) echo someone says brother at $v1
elseif ($pos(%msg, sister, 1)) echo someone says sister at $v1


Note: I added a third parameter of 1 to each use of $pos() since it seems from the context that you want it to return the first position of the word in %msg, not the number of times it appears.

#165060 21/11/06 09:27 PM
Joined: Jan 2003
Posts: 2,125
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,125
An even shorter way for those comfortable with regex is
Code:
if $regex(%msg,/.*(mother)|.*(father)|.*(brother)|.*(sister)/iU) {
  echo someone says $regml(1) at $regml(1).pos
}

Last edited by qwerty; 21/11/06 09:32 PM.
#165061 21/11/06 10:37 PM
Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
Quote:
Note: I added a third parameter of 1 to each use of $pos() since it seems from the context that you want it to return the first position of the word in %msg, not the number of times it appears.


Hm... I've used $pos without the 1 and I get the position of the first word. I don't get the number of times it appears. (v6.2)

#165062 22/11/06 12:33 AM
Joined: Dec 2002
Posts: 2,884
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,884
So it does. I didn't have mIRC available when I originally replied, I just assumed that it would default to 0 if no third parameter was given. Looking at the mIRC docs now it's not even documented that the third parameter is optional!

#165063 22/11/06 09:24 AM
Joined: Apr 2004
Posts: 755
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 755
Sorry i didnt go for shortest code there just pointing out you cant assign variable in an if evaluation like you can with php smile

#165064 22/11/06 03:00 PM
K
kaosAD
kaosAD
K
Cheers everyone!


Link Copied to Clipboard