mIRC Home    About    Download    Register    News    Help

Print Thread
Alias to read file for police "10" codes #153266 13/07/06 12:31 PM
Joined: May 2005
Posts: 449
bwr30060 Offline OP
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) $+ *)
}

Re: Alias to read file for police "10" codes #153267 13/07/06 12:41 PM
Joined: Jul 2006
Posts: 13
M
Mark_markieham Offline
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

Re: Alias to read file for police "10" codes #153268 13/07/06 12:57 PM
Joined: May 2005
Posts: 449
bwr30060 Offline OP
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.

Re: Alias to read file for police "10" codes #153269 13/07/06 01:00 PM
Joined: Jul 2006
Posts: 13
M
Mark_markieham Offline
Pikka bird
Offline
Pikka bird
M
Joined: Jul 2006
Posts: 13
It gave a random line..?

Re: Alias to read file for police "10" codes #153270 13/07/06 01:01 PM
Joined: May 2005
Posts: 449
bwr30060 Offline OP
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.

Re: Alias to read file for police "10" codes #153271 13/07/06 01:05 PM
Joined: Jul 2006
Posts: 13
M
Mark_markieham Offline
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...

Re: Alias to read file for police "10" codes #153272 13/07/06 01:08 PM
Joined: May 2005
Posts: 449
bwr30060 Offline OP
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

Re: Alias to read file for police "10" codes #153273 13/07/06 01:13 PM
Joined: Jul 2006
Posts: 13
M
Mark_markieham Offline
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

Re: Alias to read file for police "10" codes #153274 13/07/06 01:14 PM
Joined: May 2005
Posts: 449
bwr30060 Offline OP
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)
}

Re: Alias to read file for police "10" codes #153275 13/07/06 01:27 PM
Joined: Jul 2006
Posts: 13
M
Mark_markieham Offline
Pikka bird
Offline
Pikka bird
M
Joined: Jul 2006
Posts: 13
Kay smile

Re: Alias to read file for police "10" codes #153276 13/07/06 02:03 PM
Joined: Mar 2003
Posts: 612
B
billythekid Offline
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
Re: Alias to read file for police "10" codes #153277 13/07/06 11:08 PM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
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>

Re: Alias to read file for police "10" codes #153278 14/07/06 12:48 AM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
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

Re: Alias to read file for police "10" codes #153279 14/07/06 02:38 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
If it ain't broke, don't fix it.