A few things concerning the File I/O Methods in the JS engine

Need help with your JScripts? Got questions concerning the DFNs? Come forward, step inside :)
Post Reply
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

A few things concerning the File I/O Methods in the JS engine

Post by Xuri »

First: I'm toying around with the file i/o methods at the moment, but they seem a bit restrictive. According to the JS docs (and my own test), I can't search through a file for any strings longer than 2 characters, which makes it damn hard to do what I want (for instance, have a list of names or words in a txt file, and have the ability to search through that file to see if a certain word is present, if not, add it).

Secondly: Is there a way of finding out how many lines there are in a file?

And lastly: The JS Docs says:
accessMethod is a one byte string, which contains either "a" (append), "r" (read) or "w" (write).
...while I actually had to use "write" and "read" to be able to do anything =) I assume "a" should also be "append" - but what is that one used for?
-= Ho Eyo He Hum =-
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

I haven't looked at these in ages myself.

Specifically, what are you trying to achieve? One of the things I've wanted to do for a while now is expose Script/ScriptSection to the JS engine. Would this cover your needs?

As for append, it's a writing function, but what it means is that you can only write to the file *after* what is already there. You can't change what already exists, you can only add to the end of the file.
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

Basically, I need this to implement my "unique names" system for NW ;) During character creation (custom, ingame after logging in), I want the players to only be able to choose names that haven't already been taken. And to do that, I figured I could save all taken names in a txt file as they're created and check against that, instead of iterating through every single character in the world.
-= Ho Eyo He Hum =-
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

*bump*
Anyone got a clue how this can be done? :P
-= Ho Eyo He Hum =-
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

It's not out in JS yet, but yes, you could achieve this through a ScriptSection (as long as the save code is there). You'd just check for the existence of a tag which is their name, and if it's not there, it's valid, and then add it to the section. But I really need to expose this (and I will try to do so when I get the chance).
Post Reply