mIRC Homepage
Posted By: Prizm $read - 30/05/03 02:22 AM
How can I make mIRC loop through $read and return a line with no text in it?

I have a text file called rserv.txt. The contents of the file is exactly like this:

Welcome!

Please note that this server is monitored!


---

I want that to appear exactly like that when I do /loop

Here's my loop command:

Code:
alias loop {
  var %i = 1
  while ($read(rserv.txt,nt,%i)) {
    echo -a $ifmatch
    inc %i
  }
}


All my code seems to be doing is returning the 1st line. Why isn't it returning the rest of the file?
Posted By: qwerty Re: $read - 30/05/03 02:40 AM
You can't do that with $read(). You can get pretty close by using $readn or $lines() and echo a <Ctrl+B> instead of a truly blank line etc, but the recommended method for what you want is /loadbuf. Not only does it echo all the blank lines and multiple spaces but is also far faster than looping through $read().
Posted By: Prizm Re: $read - 30/05/03 02:43 AM
I need to send the text in the file through a socket. How would you recommend doing it? I was thinking of /loadbuf'ing the file into a hidden custom window and parsing it that way. Any better way?

Example:

Code:
alias loop {
  if (!$window(@rservmsg)) { window -h @rservmsg }
  loadbuf @rservmsg rserv.txt
  var %i = 1
  while ($line(@rservmsg,%i)) {
    echo -a $replace($ifmatch,$chr(32),$chr(160))
    inc %i
  }
  if ($window(@rservmsg)) { window -c @rservmsg }
}

Posted By: qwerty Re: $read - 30/05/03 02:57 AM
In this case, I'd use binary transfer, ie read 8192-byte chunks from the file to a &binvar with /bread, then /sockwrite that &binvar. There are plenty of example scripts of this kind around (I'd imagine #helpdesk's website has something relative), including some on these boards (a Search would probably reveal them).
Posted By: ScatMan Re: $read - 30/05/03 03:00 AM
your loop can be done like that:
alias loop {
var %i = 1
while (%i <= $lines(rserv.txt)) {
if ($read(ruserv.txt,%i) != $null) echo -a $ifmatch
else echo -a $chr(160)
inc %i
}
}
Posted By: Prizm Re: $read - 30/05/03 03:12 AM
That site is all messed up. I can't access any documents.
Posted By: theRat Re: $read - 30/05/03 12:15 PM
What's wrong w/ the good ol' /play
/help /play
Posted By: Prizm Re: $read - 30/05/03 01:42 PM
You can't use /play with sockets. And I need to send the contents of the text file via sockets.

OK, I tried using /bread, it seems to be doing exactly what I want, but could someone tell me if I did it correctly?

Code:
    if (($isfile(rserv.txt)) &amp;&amp; ($file(rserv.txt).size &gt; 0)) {
      bread rserv.txt 0 [color:red]$file(rserv.txt).size[/color] &amp;rserv
      sockwrite user &amp;rserv
}
Posted By: ScatMan Re: $read - 30/05/03 02:17 PM
heh no, i suggest u to send 8192 bytes each time cuz that's the maximum binary variable can store,
if ($isfile(rserv.txt)) {
var %x = 8192,%y = 0
:blah
bread rserv.txt %y %x &rserv
if ($bvar(&rserv,0)) { sockwrite user &rserv | %x = %x + 8192 | %y = %y + 8192 | goto blah }
}



Posted By: Prizm Re: $read - 30/05/03 02:21 PM
Ahhh, I see.
© mIRC Discussion Forums