mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2013
Posts: 140
R
raycomp Offline OP
Vogon poet
OP Offline
Vogon poet
R
Joined: May 2013
Posts: 140
I have funny problem when checking if a name is in a text file
names.txt file have single name per row like:
Coco
keira
linda
and so on

Quote:
on *:text:*!names*:#: {
if ($read(system\names.txt,$2)) {
.msg $chan $2 not found in names list! }
else { .msg $chan $2 found in names list. }
}


If I search for Coco
Coco found in names list!
If I search for keira
keira not found in names list.

looks like is not founding names starting with c

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
You're using the wrong syntax for $read, and then using the if() statement backwards. In effect, you're telling mIRC to display a message that the name is NOT there when the if (condition) evaluates as $true, but say the name IS there when if (condition) evaluates evaluates as $false. Your invalid syntax is using only 2 parameters, so $read assumes the 2nd parameter is the line number, but $calc(text name) is zero, so your results will be unpredictable. Some not-there names will return $null, other not-there names return a random line each time. But every name that's in the file should be returning a random name from the list.

You should get in the habit of using the n and t switch always, unless you specifically want the behavior caused by their absence. In your case, after you flip the messages for the $true and $false conditions, you should either use switch w to return the entire line for wildcard case-insensitive match of entire line vs the match pattern Coco, or use switch s to scan for line whose first word is exact match with Coco, but that returns the remainder of the line which is always $null, but you can then use $readn which contains the line number matched.

You should read the /help examples for $read for how to use $read properly, and if you need additional examples, check out the $read page at
https://en.wikichip.org/wiki/mirc/identifiers/$read


Link Copied to Clipboard