mIRC Homepage
Posted By: SCOTTiSH3LiT3 Looking For Help - 03/02/21 01:53 AM
In my script I want to read a text file when a user uses a command.

How it looks in my text file:

NICK1|2
NICK2|4

etc etc etc

I want the results to look like:

"NICK1, you have 2" or "NICK2, you have 4".

All help appreciated.
Posted By: maroon Re: Looking For Help - 03/02/21 02:06 PM
It looks like you're tokenizing your text file by the pipe symbol, which is ASCII number 124. You weren't clear whether you want a random line, or you want a line that matches the nick. For a random line, something like this would work:

var %a $read(test.txt,nt) , %nick $gettok(%a,1,124) , %have $gettok(%a,2,124)
echo -a %nick you have %have

If you are using this in the ON TEXT event then $nick has the value of the person making the message. If it's inside the nicklist's rightclick menu, then the 1st highlighted nick is in $1. Assuming the value is in $nick, you can do something like:

var %a $read(test.txt,ntw,$nick $+ $chr(124) $+ *)
if (%a != $null) {
var %nick $gettok(%a,1,124) , %have $gettok(%a,2,124)
echo -a %nick you have %have
}

The nt switches aren't needed in this situation, but it's good to always use them, especially when the content is something that could have been created by not-you. The 't' switch prevents it from trying to look at line#1 as numeric. If 't' is not used, and line 1 is a number, then that number is used instead of the REAL total-number-of-lines in the text file when returning a random line. If the file has 100 lines and line #1 is not numeric, $read(file) returns a random line from lines 1-100. But if line#1 is changed to be the number 5, then it returns a random line from within the first 5 lines excluding line 1. If not using the 'n' switch, then it tries to evaluate the line, interpreting %word as if it's a variable or $word as if an identifier, and if the line contains the pipe symbol which doesn't have text touching it, it's treated as a separator between 2 commands
Posted By: SCOTTiSH3LiT3 Re: Looking For Help - 03/02/21 03:01 PM
Originally Posted by maroon
It looks like you're tokenizing your text file by the pipe symbol, which is ASCII number 124. You weren't clear whether you want a random line, or you want a line that matches the nick. For a random line, something like this would work:

var %a $read(test.txt,nt) , %nick $gettok(%a,1,124) , %have $gettok(%a,2,124)
echo -a %nick you have %have

If you are using this in the ON TEXT event then $nick has the value of the person making the message. If it's inside the nicklist's rightclick menu, then the 1st highlighted nick is in $1. Assuming the value is in $nick, you can do something like:

var %a $read(test.txt,ntw,$nick $+ $chr(124) $+ *)
if (%a != $null) {
var %nick $gettok(%a,1,124) , %have $gettok(%a,2,124)
echo -a %nick you have %have
}

The nt switches aren't needed in this situation, but it's good to always use them, especially when the content is something that could have been created by not-you. The 't' switch prevents it from trying to look at line#1 as numeric. If 't' is not used, and line 1 is a number, then that number is used instead of the REAL total-number-of-lines in the text file when returning a random line. If the file has 100 lines and line #1 is not numeric, $read(file) returns a random line from lines 1-100. But if line#1 is changed to be the number 5, then it returns a random line from within the first 5 lines excluding line 1. If not using the 'n' switch, then it tries to evaluate the line, interpreting %word as if it's a variable or $word as if an identifier, and if the line contains the pipe symbol which doesn't have text touching it, it's treated as a separator between 2 commands






Thanks, seems to be what i was looking for and, yes, im using it with the ON TEXT event and reading per user, not at random.
Posted By: maroon Re: Looking For Help - 03/02/21 03:09 PM
i realized it's simpler to use

var %a $read(test.txt,ntw, $nick $+ |* )
Posted By: SCOTTiSH3LiT3 Re: Looking For Help - 03/02/21 04:34 PM
That worked perfectly in my bot for twitch.

Code
on *:text:!myentries:#: {
  var %a $read(giveaway.txt,ntw, $nick $+ |* )
  if (%a != $null) {
    var %nick $gettok(%a,1,124) , %have $gettok(%a,2,124)
    msg $chan %nick you have %have entries in the giveaway.
  }
}


Thanks so much!
© mIRC Discussion Forums