mIRC Home    About    Download    Register    News    Help

Print Thread
#271628 05/05/23 05:28 PM
Joined: Aug 2015
Posts: 70
Babel fish
OP Offline
Babel fish
Joined: Aug 2015
Posts: 70
Does anyone know why I would get the following error when using /write?
It works 90% of the time...

* /write: error writing 'C:\Users\Administrator\Desktop\bot2\bot4\bot2\botfiles\Today\politicsbot.05-04-2023.#wx.lines.txt' (line 332, stats.mod)

it's a strange bug...
has something to do with -dlN and/or $readn

Code
alias dostatsold {
  ;/dostatsold <N> <nick> <file> 
  if ($3 == $null) { return }
  var %file = $qt($3-), %num = $1-2
  if (!$exists(%file)) { write -c %file }
  if ($read(%file,wnt,* $2)) { %num = $calc($gettok($v1,1,32) + $1) $2 | write $+(-dl,$readn) %file }
  var %a = 1, %b, %c = $gettok(%num,1,32), %added = no
  while ($read(%file,nt,%a)) {
    %b = $v1
    if (%c >= $gettok(%b,1,32)) { write $+(-il,%a) %file %num | %added = yes | break }
    inc %a
  }
  if (%added == no) { write %file %num }
}


alias teststats {
  echo -a * Test beginning...
  var %file = undernetbot.05-05-23.#test.lines.txt
  write -c %file
  var %a = 1
  while (%a <= 300) { dostatsold $r(1,300) $gettok(entropy ent alex moo maroon Ouims westor Talon Dragon CobaltHex srolse,$r(1,11),32) %file | inc %a }
  echo -a * Done.
  run %file
}

Simply type:
Code
/teststats

for a better check, type:
Code
//var %a = 1 | while (%a <= 100) { teststats | inc %a } | echo -a * Done. 

Line 332:
Code
if ($read(%file,wnt,* $2)) { %num = $calc($gettok($v1,1,32) + $1) $2 | write $+(-dl,$readn) %file }

Thanks for your help!

Screenshot

Last edited by _entropy; 05/05/23 10:57 PM.

mIRC Scripts IRC Network: irc://irc.mircscripts.info/chat
_entropy #271738 01/06/23 08:24 AM
Joined: Dec 2002
Posts: 5,420
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,420
The reason for this is that notepad needs to access the file. If your script creates a file and then tells notepad to open it, there will be a point at which that file is locked by notepad while it loads the file. This will prevent other applications from modifying that file.


Link Copied to Clipboard