mIRC Home    About    Download    Register    News    Help

Print Thread
#52263 02/10/03 10:13 AM
Joined: Dec 2002
Posts: 4
T
Self-satisified door
OP Offline
Self-satisified door
T
Joined: Dec 2002
Posts: 4
I'm the host of two bots on a server. Information is stored in text files, and obviously I'm using $read and /write to get/write information.

A problem occurs when one bot attempts to $read a .txt at the same time the other bot is /writing to it. Is there any way to stop this? The error I get is:
* $read: error opening [file]

This error halts the script, so it's quite vital that I fix this.

Thanks in advance

#52264 02/10/03 10:20 AM
Joined: Mar 2003
Posts: 1,271
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,271
The only thing I can think of:

1. when a bot wants to access filename.txt
2. rename the file to somethingelse.txt
3. work with that
4. when done, rename back to filename.txt
5. when a bot wants to access filename.txt, check if it exists first
6. if it exists, go to step 2.
7. else, wait n seconds and try again

There's no way to check if the file is being used by another program or by which other program as far as I know.


DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius
#52265 03/10/03 11:48 AM
Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
You might want to use the new file handling functions (/help /fopen), as they speed up writing/reading a lot. Then maybe it could even get passed through this issue, I'm not sure though.

BTW, if you're using $read to read all the lines from that file, I suggest using /loadbuf instead.

Speaking of /loadbuf, if your bots were ran on the same mIRC session, you could also "cache" your file in an window, read and write info from/to it, then /savebuf on disconnect. Doing so, you'd access your file less times.


* cold edits his posts 24/7

Link Copied to Clipboard