mIRC Home    About    Download    Register    News    Help

Print Thread
using parentheses a problem? #239738 19/11/12 01:42 AM
Joined: Nov 2012
Posts: 6
C
coda2 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
C
Joined: Nov 2012
Posts: 6
How am I able to reference something in parentheses?
What I am trying to do is a line "if $1 != (rock) {" where 'rock' is my name and it will not do properly, saying that nearly everything typed for $1 will be equal to (rock). The thing might be that my nick is 'rock' and it could be confusing the thing somehow, but anything like "if $1 != (crayon) {" will work just fine.
All I really need in the end is a setup where if someone says (rock) as their first word it won't do anything, yet if they say it anywhere else or something else first it will do what I set it up to do. Any solutions?

Last edited by coda2; 19/11/12 01:43 AM.
Re: using parentheses a problem? [Re: coda2] #239742 19/11/12 11:28 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Put it into a local variable, like:
Code:
var %x = (rock)
if ($1 != %x) { stuff }

Re: using parentheses a problem? [Re: Horstl] #239746 19/11/12 05:08 PM
Joined: Nov 2012
Posts: 6
C
coda2 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
C
Joined: Nov 2012
Posts: 6
I tried that and it didn't change it. :<

Re: using parentheses a problem? [Re: coda2] #239748 19/11/12 11:57 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Originally Posted By: coda2
All I really need in the end is a setup where if someone says (rock) as their first word it won't do anything, yet if they say it anywhere else or something else first it will do what I set it up to do.
Code:
var %a = 1, %x = (rock) rock
while ($gettok(%x,%a,32)) {
if (* $+ $+(,(rock)) $+ * !iswm $strip($1-)) {
;DO NOTHING
return
}
;WHAT YOU SET OUT TO DO
return
inc %a
}

Last edited by Tomao; 20/11/12 12:00 AM.
Re: using parentheses a problem? [Re: coda2] #239749 20/11/12 12:02 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Code:
on *:text:*:#: {
  var %x = (rock)
  if (%x isin $2- && %x != $1) {
    do something
  }
}


Some notes...

If you want it to do something when that's part of $2 and on, then you want to check if it's part of $2-. You also said you don't want it to do anything if the word is in $1, so you need to also check to make sure it's not in $1. Note that this part is semi-optional. If you don't want it to ever do anything if it's in $1 even if it's in $2-, then you want to have the check preventing it from doing anything if it's in $1. If you don't care whether or not it's in $1, but only if it's in $2-, then you can leave off the $1 check and only check $2-. This depends on what exactly you want to happen with your script.

Finally, note that this example does not take into account color codes. So if someone writes (rock), it won't do anything. You can get around that by stripping control codes if you want.

EDIT: Removed the parentheses bit as it does fail after && even though it works fine as a single comparison. Basically, if you're just doing a check like if ((rock) isin $2-), then it works fine to put that directly in there, but if you're doing something like if ((rock) isin $2- && (rock) != $1), then it fails at the &&. This is due to ambiguity in the coding. The first example, mIRC can get correct, but not the second. And the first may not be correct after a new version is out somewhere down the road, so shouldn't be used.

Last edited by Riamus2; 20/11/12 12:09 AM.

Invision Support
#Invision on irc.irchighway.net
Re: using parentheses a problem? [Re: Riamus2] #239751 20/11/12 12:19 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Originally Posted By: Riamus2
Finally, note that this example does not take into account color codes.
As far as I know the isin operator will not be affected by control codes.

Re: using parentheses a problem? [Re: Tomao] #239753 20/11/12 01:20 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
It would for the example I gave because the color code is in the middle of the word. But yes, if the color was at the beginning or end, it wouldn't matter. It's usually good to use $strip() to be safe anyhow. I just left it off for as clean of an example as possible so it's easy to understand. smile


Invision Support
#Invision on irc.irchighway.net
Re: using parentheses a problem? [Re: Riamus2] #239754 20/11/12 02:45 AM
Joined: Nov 2012
Posts: 6
C
coda2 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
C
Joined: Nov 2012
Posts: 6
I guess I should note that there is color to it. When it is said, it does show up as (rock). Also, it's whenever "rock" is said that it is supposed to do the task laid out, yet I don't want it to happen if (rock) is ever the first word... It's complicated. I have tried this:
Click to reveal..
on *:text:*rock*:#:{
var %ccl as (rock)
var %cc as $strip(%ccl)
If (%cc != $1) {
;the work that'd be done
}
}

With this, it still did what was supposed to happen no matter if the first word was (rock), (rock), or not. If it was, it did the work. If rock was anywhere else, it did the work. I have also tried:
Click to reveal..
on *:text:*rock*:#:{
var %alx = 1, %ccl = (rock) rock
while ($gettok(%ccl,%alx,32)) {
if (* $+ $+(,(rock)) $+ * !iswm $strip($1-)) {
return
}
;the work that'd be done
return
inc %alx
}
}

This ended up where rock being said would do nothing at all. No matter how it was said or where, not a thing happened. It keeps thinking that whatever I have set up for "If it is not (rock)" it will always think it is not, even when it is. None of these solutions have fixed this...

Re: using parentheses a problem? [Re: coda2] #239756 20/11/12 07:46 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Have you tried Riamus2's suggestion yet?

This has to work then&#65306;
Code:
tokenize 32 $strip($1-)
var %c = (rock)
If ($1 == %c) { halt }
else { 
do something
}

Re: using parentheses a problem? [Re: coda2] #239758 20/11/12 11:21 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Note that you don't use /var with "as". The syntax is: /var %varname = value

If you want it to work regardless of parentheses, just remove them altogether.

Code:
on *:text:*:#: {
  if (rock isin $strip($2-) && rock !isin $strip($1)) {
    do something
  }
}


That will do what you want if rock is anywhere in the line as long as it isn't part of the first word. If it's part of the first word, it won't do anything even if it's found somewhere else in the line. This ignores the ()'s completely as you stated, so it doesn't matter if it's written as rock or (rock).

The one thing to note... this is a basic match. It would also match any word that has rock in it, such as crock. There aren't many words like that, so this probably won't matter. However, if it is an issue, you'd need to do some extra work. You can use $istok() to see if it's the only thing in the word, but that doesn't ignore punctuation characters or other symbols. So using $istok() by itself would match the word rock but not rock. (with the period after it). To do that you either need to $remove() all punctuation characters and symbols, or use regex to match text without punctuation. That starts to be more complicated, so you'll probably want to see how this works first and learn how it's set up before trying to make use of something like that.


Invision Support
#Invision on irc.irchighway.net
Re: using parentheses a problem? [Re: coda2] #239760 20/11/12 03:42 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Simple regex version:
Code:
on *:text:*:#:{
if (!$regex($1,/(^| )\(rock\)( |$)/iS)) && ($regex($2-,/(^| )rock( |$)/iS)) {
do something
}
}

Re: using parentheses a problem? [Re: Tomao] #239762 21/11/12 12:15 AM
Joined: Nov 2012
Posts: 6
C
coda2 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
C
Joined: Nov 2012
Posts: 6
Sorry, I don't know why I typed "as" instead of "==", but it was "==" in my script. I just typed that as I rewrote it for some reason.
One thing I've said already, is that I want it to respond when "rock" is said, but when the first word is not "(rock)". The first part of that I have covered, but it's the second that is the problem.
Somehow, the "if (!$regex($1,/(^| )\(rock\)( |$)/iS)) && ($regex($2-,/(^| )rock( |$)/iS)) {" line ended up working, but I don't like it. It doesn't work if any word is (rock), even though if (rock) is the second, third, etc. word I want it to work. Also what if the first word is "rock"? Will it still react then? Again, "rock" != "(rock)"... It's complicated. If "(rock)" was anything /but/ the first word, I'd still want it to work.
Again, "if rock !isin $strip($1) {" isn't entirely what I want, not at all...
To say things yet again, I want the script to do what I want it to do whenever "rock" is said, yet not if the first word is "(rock)". Anything of the following should cause a reaction: "blah (rock) blah", "rock (rock) rock (rock) blah", "rock blah rock", etc. Buuuuut, "(rock) blah", or more particularly "(rock) blah" should cause nothing.
But, particularly this version works well enough for me to be satisfied. The chances that (rock) would be said at any time other than as the first word are slim, so it's okay.
And for the "crock" side note, I've got those possibilities covered separately.

Last edited by coda2; 21/11/12 12:17 AM.