mIRC Home    About    Download    Register    News    Help

Print Thread
Unloading all scripts - Weird Error #78040 05/04/04 01:38 PM
Joined: Apr 2004
Posts: 9
T
TristanWolf Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Apr 2004
Posts: 9
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)

Re: Unloading all scripts - Weird Error #78041 05/04/04 01:48 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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
  }
}


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Unloading all scripts - Weird Error #78042 05/04/04 05:37 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: Unloading all scripts - Weird Error #78043 05/04/04 10:28 PM
Joined: Apr 2004
Posts: 9
T
TristanWolf Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Apr 2004
Posts: 9
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.

Re: Unloading all scripts - Weird Error #78044 05/04/04 10:32 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Unloading all scripts - Weird Error #78045 05/04/04 10:46 PM
Joined: Apr 2004
Posts: 9
T
TristanWolf Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Apr 2004
Posts: 9
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.

Re: Unloading all scripts - Weird Error #78046 05/04/04 11:24 PM
Joined: Apr 2004
Posts: 9
T
TristanWolf Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Apr 2004
Posts: 9
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