'mIRC/mSL pulling certian strings out of a wildcard
So I'm pretty new to mSl scripting, but I've done some other scripting before. I'm trying to figure out how to do some pattern matching, but I'm having a problem. Let's say I have the following text
Someone has flipped a coin to Jim and it was head.
I'm wanting to find out if the coin ended up being heads or tails. I thought it would be something like
on *:text:*flipped a coin * and it was *:#:{echo -a the coin was $3}
but it seems like the $ operator is taking the 3rd word from the complete wildcard. I might be able to figure out how to get it right with this example, but lets say we have the following examples with multiple coins
Someone flipped a coin to Dave and it was tails, and also filled a coin to Jim and it was heads.
I'm wanting to find out what coin Jim had, but I don't know how many people were before or after him, so finding the xth word in my wild card won't work. What i'd like to do is something like this (mostly sudo code)
on *:text:$1 * to Jim and it was $2:#:{
echo -a $1 is who flipped it to Jim and it was $2
}
Where I can basically throw out my wildcards and now i can directly reference who the coin flipper was, and what the results were.
Thanks for any help!
Edit:
I'm able to find the find the coin result with regex, but I'm not sure how to pull the result out in mirc. See the regex pattern i'm using here . I tried using $regex in mirc and also $regml, but it's not working right. I currently have the following in my script:
on $*:text:/Jim and it was (\b\w{5}\b)/iS:#:{
echo -a $regex(currCoin, $1-,Jim and it was (\b\w{5}\b))
echo -a $regml(currCoin,0)
echo -a $regml(currCoin,1)
}
I thought $regex would essentially save the groups from my regex to currCoin, and then $regml would display the Nth group value, sort of like $N would show the Nth group value in regex. I'm clearly miss understanding something though.
Solution 1:[1]
You can use token identifiers instead of regex for this. I haven't used msl for at least 10 years, so bear with me.
on *:text:*to Jim and it was*:#:{
var %jimpos = $findtok($1-,Jim,1,32)
var %coinpos = %jimpos + 4
var %result = $gettok($1-,%coinpos,32)
msg $chan $remove(%result,.)
}
You can possibly shorten it somewhat or do more operations on the same line, but this is readable at least.
Solution 2:[2]
on *:action:$(*has flipped a coin to $6 and it was $10 $+ *):#: {
var %coin.1,%coin.2, %user.1, %user.2
%user.1 = $6
if (head isin $10) { %coin.1 = heads }
if (tail isin $10 { %coin.1 = tails }
if (*and also filled a coin to ?* and it was ?????. iswm $1-) {
%user.2 = $17
if (head* iswm $21) { %coin.2 = heads }
else { %coin.2 = tails }
}
echo $nick says he/she flipped a coin to %user.1 $iif(%user.2,and %user.2)
}
Just make sure you always use the same amount of words in each sentence. So if you say "HAS flipped a coin..." you need to always word it with the words "has flipped ..."
You may notice I used on :action::#: instead of on :text::#: this is detecting /describe #chan text. Also known as /me or /action.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | melwil |
Solution 2 |