mIRC Homepage
Posted By: quiglag reading from file comes out backwards - 11/06/05 06:46 PM
OK, so this script is reading from a text file like this:

---------txtfile-----
line1
line2
line3
line4
.....
---------------------

But the output shows up as: line4, line3, line2, line1
I want it to output like:line1, line2, line3, line4

Here is part of the code
Code:
 

...
if ($read(list.txt,w,$+(*,$nick,*))) {
      var %x = $lines(list.txt), %target
        while (%x) {
          var %target = $addtok(%target, 7 $+ $chr(32) $gettok($read(list.txt,%x),1,32) $+  ,44) 
          dec %x
      }
      msg $chan list is:7  %target
...


thanks
Posted By: Rumie Re: reading from file comes out backwards - 11/06/05 08:24 PM
use inc not dec the while loop
Posted By: xDaeMoN Re: reading from file comes out backwards - 11/06/05 08:36 PM
try this

Code:
 if ($read(list.txt,w,$+(*,$nick,*))) {
      var %x = 1, %target
        while $read(list.txt,%x) {
          %target = $addtok(%target, 7 $+ $chr(32) $gettok($v1,1,32) $+  ,44) 
          inc %x
      }
      msg $chan list is:7  %target
 
Posted By: quiglag Re: reading from file comes out backwards - 11/06/05 09:44 PM
That did it smile Thanks
Posted By: quiglag Re: reading from file comes out backwards - 11/06/05 10:00 PM
Now if I only wanted to msg the first 3 lines or 5 lines of the list, what part of the script would change? Thanks
Posted By: xDaeMoN Re: reading from file comes out backwards - 11/06/05 10:32 PM
Change this line

Code:
 while $read(list.txt,%x) { 


to

Code:
 while ( $read(list.txt,%x) ) && ( %x <= 3 )  { 


** Change 3 to your desired number
Posted By: quiglag Re: reading from file comes out backwards - 11/06/05 11:07 PM
I tried it and it doesnt work. If i set it to 5, it outputs numbers 1, 2, 3, 4, 5, it doesnt read the first 5 from the list.

Thanks
Posted By: tidy_trax Re: reading from file comes out backwards - 11/06/05 11:18 PM
That won't work because $v1 is set to the %x in this situation, you can simply reverse your if statement and it will work.

Code:
while ( %x <= 3 ) && ( $read(list.txt,%x) ) { 
Posted By: quiglag Re: reading from file comes out backwards - 11/06/05 11:54 PM
That works. Thanks smile
Posted By: xDaeMoN Re: reading from file comes out backwards - 12/06/05 12:12 AM
Oh yeah, that's right. Thanks for fixing it.
© mIRC Discussion Forums