mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2005
Posts: 449
Fjord artisan
OP Offline
Fjord artisan
Joined: May 2005
Posts: 449
I'm trying to write an alias to echo a line from a text file depending on what parameters I give it. The text file looks like this:
Quote:

10-0 Use caution
10-1 Unable to copy location
10-2 Signal Good
10-3 Stop transmitting


For example, I'd like to type /ten 3 and have it echo "10-3 Stop transmitting". I've tried this but it isn't working.
Code:
/ten {
  echo -a  $read(ten.txt,w, $matchtok($1-, 10, 1,32) $+ *)
}

Joined: Jul 2006
Posts: 13
M
Pikka bird
Offline
Pikka bird
M
Joined: Jul 2006
Posts: 13
Code:
 /ten {
   if ($1 isnum) {
     var %linenum = $calc($1 + 1)
     var %text = $read(ten.txt, %linenum)
     echo -a Warning: %text
   }
   else echo -a Choose a number you fool!
} 


It first checks if you supply a number. Then it reads the line with that number + 1, so you need to have 10-0 Use Caution on line 1 in the file, 10-1 Unable to copy location on line 2 and so on.


Note: Haven't tested it.. But i think it should work like that :P

Joined: May 2005
Posts: 449
Fjord artisan
OP Offline
Fjord artisan
Joined: May 2005
Posts: 449
Thanks, that works partially. I have some problems with it. I typed /ten 76 and I got the line for 10-75. I also typed /ten 77 and got the line for 10-76. I checked the file and they're all number sequentially up to that point at least, so it's not the text file throwing it off.

Joined: Jul 2006
Posts: 13
M
Pikka bird
Offline
Pikka bird
M
Joined: Jul 2006
Posts: 13
It gave a random line..?

Joined: May 2005
Posts: 449
Fjord artisan
OP Offline
Fjord artisan
Joined: May 2005
Posts: 449
No, it looks like it gave the line for the code I wanted - 1, example, I wanted 10-76 and it gave me 10-75.

Joined: Jul 2006
Posts: 13
M
Pikka bird
Offline
Pikka bird
M
Joined: Jul 2006
Posts: 13
I don't understand it...

Copy/paste what it shows please?

Then i can figure out what's wrong...

Joined: May 2005
Posts: 449
Fjord artisan
OP Offline
Fjord artisan
Joined: May 2005
Posts: 449
I have
Code:
/ten {   
  if ($1 isnum) {     
    var %linenum = $calc($1 + 1)     
    var %text = $read(ten.txt, %linenum)     
    echo -a %text   
  }   
  else echo -a Choose a number you fool!
}


I type /ten 76 and I get
Quote:

10-75 In contact with ____


I type /ten 100 and I get
Quote:

10-99 Warrant/Stolen indicated

Joined: Jul 2006
Posts: 13
M
Pikka bird
Offline
Pikka bird
M
Joined: Jul 2006
Posts: 13
Are you sure you're not missing 2 somewhere?

Does this also show for /ten 4 as example?


mark

Joined: May 2005
Posts: 449
Fjord artisan
OP Offline
Fjord artisan
Joined: May 2005
Posts: 449
I just figured something out. This does what I want.
Code:
/ten {
  var %scan = 10- $+ $1
  echo -a $read(ten.txt,s,%scan)
}

Joined: Jul 2006
Posts: 13
M
Pikka bird
Offline
Pikka bird
M
Joined: Jul 2006
Posts: 13
Kay smile

Joined: Mar 2003
Posts: 612
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Mar 2003
Posts: 612
scannign for the match is a much better way of managing it as there might be no x code or line that matches the code you are looking for, or might have a line missing or be other text in the file before the codes.

you might want to throw up a if $2 > maxtencodes echo no such code

or similar.

btk


billythekid
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Try this little code. I don't have the 10 codes in a text file, so I haven't tested this, but I don't see any reason for it to not work
Code:
 alias ten {
  set %code $iif($read(ten.txt,nw,$+(10-,$1,*)),$v1,No code match)
  $iif($isid,return,echo -a) %code
}
 


Usage: $ten(<ten_code>) or /ten <ten_code>

Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Quote:
Try this little code. I don't have the 10 codes in a text file, so I haven't tested this, but I don't see any reason for it to not work
Code:
 alias ten {
  [color:red]set[/color] %code $iif($read(ten.txt,nw,$+(10-,$1,*)),$v1,No code match)
  $iif($isid,return,echo -a) %code
}
 


Usage: $ten(<ten_code>) or /ten <ten_code>



shocked

/me demotes RusselB

-genius_at_work

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
If it ain't broke, don't fix it.


Link Copied to Clipboard