mIRC Homepage
Posted By: TristanWolf Unloading all scripts - Weird Error - 05/04/04 01:38 PM
Good morning all!

This problem is baffling me. I'm attempting to create an alias that unloads all scripts, besides the current one, and then load all scripts from a specific folder (a reload function - that would apply to new scripts in the subfolder). Here's what I have so far:

Code:
[script]
alias reload {
  var %Count = 1

  ;  Unload all current scripts, except the current script
  while ( $script(%Count) != $null ) { 
    if ( $script(%Count) != $script ) { /unload -rs $script(%Count) }
    inc %Count
  }
}


I get a wierd error that it can't find My Documents are some nonsense.

Any advice is greatly appreciated here. Thanks a bunch in advance.

Have a great day all (even if it is a Monday grin)
When giving filenames as a parameter you need to have double-quotes around them if they contain spaces (added code highlighted in red). Also, you can improve the efficiency of that script by using $ifmatch in place of the second two instances of $script(%Count).
Code:
alias reload {
  var %Count = 1
  ; Unload all current scripts, except the current script
  while ( $script(%Count) != $null ) { 
  if ( [color:blue]$script(%Count)[/color] != $script ) { /unload -rs [color:red]$+(", [color:blue]$script(%Count)[/color], ")[/color] }
  inc %Count
  }
}
Posted By: qwerty Re: Unloading all scripts - Weird Error - 05/04/04 05:37 PM
Apart from your remarks, there is a logical error in this script. Let's assume that the current script (the one that contains /reload) is #2. When %count is 3, mirc will unload the 3rd script. But this way, the 4th script now becomes the 3rd, the 5th becomes the 4th and so on. So by always /inc-ing the variable, you miss out items. The simplest fix here would be to replace inc %count with else inc %count.

Also, the alias name /reload may not be the best choice, since /reload is an internal mirc command.
Posted By: TristanWolf Re: Unloading all scripts - Weird Error - 05/04/04 10:28 PM
Thanks for your help.

Got me past that point.

Unfortunately, still having problems. Here's the current code:

Code:
alias reloadtest {
  var %Count = 1
  var %Total = $script(0) + 1

  ;  Unload all current scripts, except the current script
  while ( %Count != %Total ) {
    if ( $script(%Count) != $script ) {
      var %File = $chr(34) $+ $script(%Count) $+ $chr(34)
      echo %File
      unload -rs %File
    }
    inc %Count
  }
}


It unloads a couple of files and then errors out with...

Code:
* /unload: insufficient parameters (line 10, reload.ini)


Any ideas? Thanks again for your help.
That would be because of what qwerty described, simply change the inc %Count line to else inc %Count so that it will only be incremented if a file wasn't unloaded.
Posted By: TristanWolf Re: Unloading all scripts - Weird Error - 05/04/04 10:46 PM
Have I told you guys how awesome you are?

No?

<ahem>

You guys are awesome.

Here's my semi-finished code:

Code:
alias ReloadAllScripts {
  var %Count = 1

  ;  Unload all current scripts, except the current script
  while ( $script(0) &gt; 1 ) {
    if ( $script(%Count) != $script ) {
      .unload -rs $chr(34) $+ $script(%Count) $+ $chr(34)
    }
    else { inc %Count }
  }
}


That look good to you?

Thanks again for all of your help.
Posted By: TristanWolf Re: Unloading all scripts - Weird Error - 05/04/04 11:24 PM
Finalized code. Figured you guys might wanna see what I'm going with here.

Basically, the concept is to have two subfolders in the mIRC directory. One for scripts and the other for the users file.

Anyway, here's, at least for now, the final draft:

Code:
on admin:TEXT:.Reload*:?:{
  ReloadAllScripts
  ReloadUsers
  msg $nick Reload: Complete.
  ReloadCurrent
}

alias ReloadAllScripts {
  ;  Unload all current scripts, except the current script
  var %Count = 1
  while ( $script(0) &gt; 1 ) {
    if ( $script(%Count) != $script ) {
      .unload -rs $chr(34) $+ $script(%Count) $+ $chr(34)
    }
    else { inc %Count }
  }
  ;  Load all scripts in the current script directory, except the current script
  var %Count = 1
  while ( $findfile($scriptdir,*.ini,%Count) &gt; != $null ) {
    if ( $findfile($scriptdir,*.ini,%Count) != $script ) {
      .load -rs $chr(34) $+ $findfile($scriptdir,*.ini,%Count) $+ $chr(34)
    }
    inc %Count
  }
}

alias ReloadCurrent {
  ;  Reload the current script
  .reload -rs $chr(34) $+ $script $+ $chr(34)
}

alias ReloadUsers {
  ;  Reload the current users file
  .reload -ru Users\Users.ini
}


grin
© mIRC Discussion Forums