|
|
Joined: Apr 2004
Posts: 9
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
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: [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  )
|
|
|
|
Joined: Dec 2002
Posts: 2,884
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,884 |
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). 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
}
}
|
|
|
|
Joined: Jan 2003
Posts: 2,125
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,125 |
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.
|
|
|
|
Joined: Apr 2004
Posts: 9
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Apr 2004
Posts: 9 |
Thanks for your help. Got me past that point. Unfortunately, still having problems. Here's the current 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... * /unload: insufficient parameters (line 10, reload.ini) Any ideas? Thanks again for your help.
|
|
|
|
Joined: Dec 2002
Posts: 2,884
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,884 |
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.
|
|
|
|
Joined: Apr 2004
Posts: 9
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
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: alias ReloadAllScripts {
var %Count = 1
; Unload all current scripts, except the current script
while ( $script(0) > 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.
|
|
|
|
Joined: Apr 2004
Posts: 9
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
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: 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) > 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) > != $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
}
|
|
|
|
|
|