mIRC Home    About    Download    Register    News    Help

Print Thread
#26928 29/05/03 05:27 PM
Joined: Apr 2003
Posts: 414
Fjord artisan
OP Offline
Fjord artisan
Joined: Apr 2003
Posts: 414
Get the disk's number .. Like $disk(0) - must return number of the disk's ..


mIRC Chm Help 6.16.0.3 Full Anchored!
#26929 30/05/03 02:20 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Until it gets implemented, check out this alias:
Code:
[color:green]; Usage: $diskn(N,type).prop
; Returns the Nth drive letter of the specified type.
; The <type> parameter is optional, if it is omitted,
; all existing disks are taken into account.
; If N is 0 (or non-numeric) it returns the
; total number of disks (of the specified type, if 
; the <type> parameter is present)
; prop can be whichever property is supported by
; mIRC's $disk()
; Examples: 
; $disk(0) -> returns the total number of drives
; $disk(3) -> returns the letter of the 3rd drive
; $disk(0,fixed) -> returns the total number of hard disk drives
; $disk(1,fixed) -> returns the letter of the 1st hard disk drive (normally C)
; $disk(2,cdrom).label -> returns the volume label of the 2nd CD-ROM drive[/color]
alias diskn {
  if * !iswm $1 { return }
  if !%drives { makedriveslist }
  if $1 !isnum 1- { return $wildtok(%drives,$+(*:,$2,*),0,32) }
  if $istok(type free label size unc,$prop,32) { return $disk($gettok($wildtok(%drives,$+(*:,$2,*),$1,32),1,58)). [ $+ [ $prop ] ] }
  return $gettok($wildtok(%drives,$+(*:,$2,*),$1,32),1,58)
}

[color:green]; The following alias caches the drives info in a global 
; variable named %drives, so that the $diskn() alias doesn't 
; have to retrieve it every time.
; $diskn() re-retrieves the drives information if
; the %drives variable isn't found; so to clear the
; cached info and force an update just unset %drives
; A perhaps good idea is to call /makedriveslist
; during mIRC startup, with something like:
; on *:start: makedriveslist[/color]
alias makedriveslist {
  unset %drives
  var %i = 65
  while %i < 91 {
    if $disk($chr(%i)).type { 
      %drives = %drives $+($chr(%i),:,$ifmatch)
    }
    inc %i
  }
}



/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#26930 30/05/03 03:50 AM
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Is if * !iswm $1 { return } really faster than
if !$1 { return }?


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
#26931 30/05/03 04:22 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
No, it's just different :tongue: You probably know that if !$1 means "if $1 is $null OR $false OR 0". In $diskn(), 0 is an acceptable value (returning the total number of drives), $null is not. So I need something like if $1 != $null. This one is slightly slower than if * !iswm $1. I would assume that the difference isn't noticeable in the vast majority of scripts but I always tend to use the faster alternative, unless there are other more important reasons to do otherwise.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#26932 30/05/03 06:07 AM
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Ah, i see.
I suppose there's always (!$0) but your method is just as good. It just struck me as an interesting habitual way of checking for valid parameters.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
#26933 30/05/03 11:23 AM
Joined: Apr 2003
Posts: 414
Fjord artisan
OP Offline
Fjord artisan
Joined: Apr 2003
Posts: 414
Thank you smile


mIRC Chm Help 6.16.0.3 Full Anchored!
#26934 30/05/03 11:36 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Yeah, there's if !$0, but there is a subtle difference for custom identifiers: in a call like $diskn($null), $0 returns 1, although the 1st parameter is $null.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Link Copied to Clipboard