mIRC Home    About    Download    Register    News    Help

Print Thread
#176238 06/05/07 06:52 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
Someone that can spot any problem in this code?
Code:
alias adddir {
  set %mp3dir $sdir="Select a dir:"
  if (%mp3dir == $null) { halt }
  else {
    set %mp3.num $findfile(%mp3dir, *.mp3, 0)  
    set %mp3.loop 1
    if ($lines(" $+ $mircdir\mp3list.txt $+ ") == 0) { did -r playlist 1 }
    :loop
    if (%mp3.loop <= %mp3.num) { 
      set %mp3dir $remove(%mp3filename,$nopath(%mp3filename))
      write " $+ $mircdir\mp3list.txt $+ " $findfile(%mp3dir,*.mp3,%mp3.loop)
      inc %mp3.loop
      goto loop
    }
    else { loadplaylist }
  }
}

it working fine 1 time, then the next it wont work at all.. any ideas?


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
I can't see the problem off the top of my head, but there's a huge amount of room for improvement:

Code:
alias adddir {
  if (!$lines(mp3list.txt)) { did -r playlist 1 }
  noop $findfile($sdir($mp3dir,Select a dir),*.mp3,0,write mp3list.txt $1-)
  loadplaylist
}


Problems with yours:

1) You unnecessarily use $mircdir. Using just 'file.txt' is equivalent to '$mircdirfile.txt'
2) You unnecessarily use double quotes for filenames when passed to identifiers. Identifiers don't require filename parameters to be quoted, only commands do.
3) You loop with $findfile when it has built-in loop functionality, which is an absolutely huge more efficient method than looping with goto/while.
4) You use goto loops, which are awful and haven't been needed for many mIRC versions since mIRC now supports while loops.
5) You use global variables which you only need during the alias. You should use local variables.
6) Checking if ($lines() == 0) can be replaced with if (!$lines())

Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031
Aside from that it's perfect? smirk

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
Another reason he shouldn't be re-defining the %mp3dir inside his loop, is because not re-setting the value allows the default dir to be the last dir you used, assuming it's likely that the next dir you grab would be near the prior one, ie:

set %mp3dir $sdir="Select a dir:" %mp3dir $+ \


Link Copied to Clipboard