Can anyone take a look at the code below and assist me in correcting the error?
Error:
* /write: error writing 'C:\Users\Profile Name\AppData\Roaming\mIRC\scripts\data\AutoJoin.mrk' (line 65, script1.ini)
NOTE: Profile Name is where my full name is
alias find_cboxai {
if $dialog(autos) {
var %c = $read($_doc(AutoID),$calc(%_i -1)),%g = $gettok(%c,2-,42)
THIS IS LINE 65 write -l $+ $calc(%_i -1) $_doc(AutoID) $gettok($did(autos,8,%_i),5,32) $+ * $+ %g
inc %_i
}
}
alias rconf {
if $dialog(autos) {
if ($1-2) { return $readini($+(",$mircdirscripts\data\autos.ini,"),$1,$2) }
}
}
alias conf {
if $dialog(autos) {
if ($1) && ($2) && ($3) { writeini $+(",$mircdirscripts\data\autos.ini,") $1 $2 $3- } | else { return }
}
}
alias _doc { return $+(",$mircdirscripts\data\,$1,.mrk,") }
Button 6 = Dialog Close Button
on *:dialog:autos:sclick:6: {
conf Autos Join $iif($did($dname,3).state = 1,on,off)
conf Autos Identify $iif($did($dname,9).state = 1,on,off)
conf Autos IDEvent $iif($did($dname,13).sel = 1,connect,notice)
set %_i 2
filter -k $_doc(AutoJoin) find_cboxaj
set %_i 2
filter -k $_doc(AutoID) find_cboxai
unset %_i
}
I'm not seeing something that would cause this. The 'error writing' message is ambiguous. "error opening" would mean either the foldername or filename doesn't yet exist, but "error writing" means the filename does exist. There are a couple of causes I can think of, but they shouldn't be happening in this context.
The file could have the 'read only' attribute set, but this is unlikely unless it was specifically set due to being copied off a CD/DVD media where it was set, or if you specifically set it. You can verify this isn't the case by doing:
/run cmd /k attrib scripts\data\AutoJoin.mrk
Typically there would only be the A attribute to the left of the filename, and there should not be the "R" for read-only.
If there is the R attribute, you can remove it like
/run cmd /c attrib -r scripts\data\AutoJoin.mrk
The error could be caused by not having write permissions to the file, but this shouldn't happen unless you're doing something like writing to a subfolder beneath c:\program files\ or c:\windows\
It's still possible for a file to have blocked write permissions if you used a utility to 'move' the filename from another folder where you didn't have write permissions. If that's the case, you'd want to *move* it back there, then *copy* it here.
==
A couple other suggestions for your script:
+ Use relative pathnames, so you don't need to put quotes around everything to protect against $mircdir having a space in it. By default, if the pathfilename doesn't begin with \ or driveletter:\ then it carries an implied $mircdir in front of it, so you could change _doc to
alias _doc { return $+(scripts\data\,$1,.mrk) }
Also, you want to get in the habit of using switches with $read.
If you don't want to have it evaluate %variable or $identifier contained in the returned text, nor for it to waste time looking for it, then use the r switch.
If you don't want to have it waste time checking if line#1 is numeric, and if that's so, to have it treat that as if it's the number of lines in the file, then use the t switch.
Since you're using a .ini format the 't' issue isn't probably going to affect you, and you're probably not reading/writing strings containing words that being with $ or %, but it's good practice to be in the habit of using switches rt unless you DO want that behavior, and have taken steps to ensure that any text has been sanitized before being written to that file.
Thank you for your response however I've checked and the files are not write protected. Basically when clicking on the Close button that error occurs and is related to the check/uncheck of the checkbox in the list of nicks/passwords and/or list of auto join channels. The boxes are checked by default and when unchecked they do not uncheck.
; ## On CONNECT
on *:connect: {
if ($rconf(Autos,Join) = on) { .timer 1 1 _aj }
if ($rconf(Autos,Identify) = on) && ($rconf(Autos,IDevent) = connect) && ($network != UnderNet) && ($network != QuakeNet) { _id $cid }
elseif ($rconf(Autos,Identify) = on) && ($network = QuakeNet) || ($network = UnderNet) { _id $cid }
}
; ## on NOTICE
on *:notice:*:*: {
if ($rconf(Autos,Identify) = on && $rconf(Autos,IDEvent) = notice) {
if ($nick = Nickserv) {
if (*identify* iswm $1-) { _id $cid }
}
}
}
; ## Join channels on active network
alias _aj {
var %i = 1,%n = $network
while %i <= $lines($_doc(Autojoin)) {
var %r = $read($_doc(Autojoin),%i)
if ($gettok(%r,3,42) = %n) && ($gettok(%r,1,42) = 2) {
join $gettok(%r,2,42) $iif($gettok(%r,4,42),$ifmatch)
}
inc %i
}
}
; ## Identify to active nickname on active network
alias _id {
var %cid = $1
var %i = 1
while (%i <= $lines($_doc(AutoID))) {
if ($me = $gettok($read($_doc(AutoID),%i),2,42) && $network = $gettok($read($_doc(AutoID),%i),3,42)) && ($gettok($read($_doc(AutoID),%i),1,42) = 2) {
if (%cid) scid %cid $gettok($read($_doc(AutoID),%i),5-,42) $gettok($read($_doc(AutoID),%i),4,42))
else { $gettok($read($_doc(AutoID),%i),5-,42) $gettok($read($_doc(AutoID),%i),4,42)) }
}
inc %i
}
unset %cid
}
; ## Call module dialog
alias _autos { dodialog autos }
; ## Check if state is on or off (autojoin)
alias conf { if ($1) && ($2) && ($3) { writeini $+(scripts\data\autos.ini) $1 $2 $3- } | else { return } }
alias rconf { if ($1-2) { return $readini($+(scripts\data\autos.ini),$1,$2) } }
alias _doc { return $+(scripts\data\,$1,.ini) }
alias find_cboxaj {
if $dialog(autos) {
var %c = $read($_doc(AutoJoin),$calc(%_i -1)),%g = $gettok(%c,2-,42)
write -l $+ $calc(%_i -1) $_doc(AutoJoin) $gettok($did(autos,2,%_i),5,32) $+ * $+ %g
inc %_i
}
}
; ## Load autojoin information to list
alias load_aj {
if $dialog(autos) {
did -a autos 2 $gettok($1-,2,42) $chr(9) $gettok($1-,3,42) $chr(9) $iif($gettok($1-,4,42),$ifmatch,-)
did -o autos 2 %_i 0 0 0 $gettok($1-,1,42) $gettok($did(autos,2,%_i),6-,32))
inc %_i
}
}
; ## Load auto identify information to list
alias load_ai {
if $dialog(autos) {
did -a autos 8 $gettok($1-,2,42) $chr(9) $gettok($1-,3,42) $chr(9) $str(*,$len($gettok($1-,4,42))) $chr(9) $gettok($1-,5-,42)
did -o autos 8 %_i 0 0 0 $gettok($1-,1,42) $gettok($did(autos,8,%_i),6-,32))
inc %_i
}
}
; ## Check if state is on or off (auto identify)
alias find_cboxai {
if $dialog(autos) {
var %c = $read($_doc(AutoID),$calc(%_i -1)),%g = $gettok(%c,2-,42)
write -l $+ $calc(%_i -1) $_doc(AutoID) $gettok($did(autos,8,%_i),5,32) $+ * $+ %g
inc %_i
}
}
; ## Auto join/identify dialog table/events
dialog autos {
title "Auto Join/Identify"
size -1 -1 169 167
option dbu notheme
tab "Auto Join", 1, 2 31 164 117
list 2, 5 51 158 79, tab 1 size
check "Enable", 3, 5 133 37 12, tab 1 push
button "Add", 4, 86 133 37 12, tab 1
button "Delete", 5, 126 133 37 12, tab 1
tab "Auto Identify", 7
list 8, 5 51 158 79, tab 7 size
check "Enable", 9, 5 133 37 12, tab 7 push
button "Add", 10, 86 133 37 12, tab 7
button "Delete", 11, 126 133 37 12, tab 7
text "Identify on:", 12, 3 155 29 8, tab 7
combo 13, 35 153 43 50, tab 7 size drop
button "&Done", 6, 130 153 37 12, ok
text "", 14, 2 3 165 26
list 15, 143 6 21 18, disable size
text " - set up channels to join and nicknames to identify to on connect", 16, 3 13 121 13
text " Auto Join/Identify", 17, 3 5 68 7
}
on *:dialog:autos:init:0: {
dicon $dname $script
$iif(!$isfile($_doc(AutoID)),.write -c $_doc(AutoID))
$iif(!$isfile($_doc(AutoJoin)),.write -c $_doc(AutoJoin))
mdx.load
mdx SetFont $dname 2,4,5,6,8,10,11,12,13 12 550 Verdana
mdx SetFont $dname 3,9 12 700 Verdana
mdx SetFont $dname 17 -11 700 Tahoma
mdx SetColor $dname 17 text $rgb(255,255,255)
mdx SetColor $dname 14,16,17 background $rgb(111,132,161)
mdx SetColor $dname 14,16,17 textbg $rgb(111,132,161)
mdx SetBorderStyle $dname 14 staticedge
mdx SetControlMDX $dname 15 Toolbar flat wrap nodivider list > $bars
mdx SetBorderStyle $dname 15
mdx SetColor $dname 15 background $rgb(111,132,161)
did -i $dname 15 1 bmpsize 32 32
did -i $dname 15 1 setimage icon large $icon1
did -a $dname 15 +a 1 $chr(9) Nothing
mdx SetControlMDX $dname 2,8 Listview report single rowselect checkboxes > $views
did -i $dname 2 1 headerdims 130 110 72
did -i $dname 2 1 headertext Channel $chr(9) Network $chr(9) Key
did -i $dname 8 1 headerdims 100 100 90 100
did -i $dname 8 1 headertext Nickname $chr(9) Network $chr(9) Password $chr(9) String
didtok $dname 13 32 Connect Notice
$iif($rconf(Autos,Join) = on,did -c $dname 3)
$iif($rconf(Autos,Identify) = on,did -c $dname 9)
$iif($rconf(Autos,IDEvent) = connect,did -c $dname 13 1,did -c $dname 13 2)
set %_i 2
.filter -k $_doc(AutoJoin) load_aj
set %_i 2
.filter -k $_doc(AutoID) load_ai
unset %_i
}
on *:dialog:autos:sclick:4: {
var %c = $$?="Enter channel:",%n = $$?="Enter network:"
if %c && %n {
var %k = $?!="Is there a key?"
if %k = $true {
%k = $$?="Enter channel key"
write $_doc(AutoJoin) $+(2,*,%c,*,%n,*,%k)
}
else {
write $_doc(AutoJoin) $+(2,*,%c,*,%n)
}
did -r autos 2
set %_i 2
.filter -k $_doc(AutoJoin) load_aj
unset %_i
}
}
on *:dialog:autos:sclick:5: {
if $did($dname,2).sel {
var %s = $calc($ifmatch -1)
write -dl $+ %s $_doc(AutoJoin)
did -r autos 2
set %_i 2
filter -k $_doc(AutoJoin) load_aj
unset %_i
}
}
on *:dialog:autos:sclick:6: {
conf Autos Join $iif($did($dname,3).state = 1,on,off)
conf Autos Identify $iif($did($dname,9).state = 1,on,off)
conf Autos IDEvent $iif($did($dname,13).sel = 1,connect,notice)
set %_i 2
filter -k $_doc(AutoJoin) find_cboxaj
set %_i 2
filter -k $_doc(AutoID) find_cboxai
unset %_i
}
on *:dialog:autos:sclick:10: {
var %c = $$?="Enter nickname:",%n = $$?="Enter network:",%p = $$?="Enter password:",%s = $$?="Enter string to identify:"
if %c && %n && %p && %s {
write $_doc(AutoID) $+(2,*,%c,*,%n,*,%p,*,%s)
did -r autos 8
set %_i 2
.filter -k $_doc(AutoID) load_ai
unset %_i
}
}
on *:dialog:autos:sclick:11: {
if $did($dname,8).sel {
var %s = $calc($ifmatch -1)
write -dl $+ %s $_doc(AutoID)
did -r autos 8
set %_i 2
filter -k $_doc(AutoID) load_ai
unset %_i
}
}
I'm not seeing a problem. When you have trouble with a script, it's often helpful to insert debug messages so you can see what the parameters are as of that line. In this case, with your error happening on this line:
write -l $+ $calc(%_i -1) $_doc(AutoID) $gettok($did(autos,8,%_i),5,32) $+ * $+ %g
Then insert a line above it like:
echo -s debug: $_doc(AutoID) $lines($_doc(AutoID)) //write -l $+ $calc(%_i -1) $_doc(AutoID) $gettok($did(autos,8,%_i),5,32) $+ * $+ %g
this lets you see how many lines were in the file at the time of the write attempt, and whether the filename existed. It shows the command that you can try repeating from the command line.
Something else to try:
I notice you're trying to mix /writeini and /write to the same filename. See if it helps if you place above the offending /write commands:
flushini $_doc(AutoID)