Page 1 of 1

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

Posted: Wed Feb 15, 2006 11:52 am
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?

Posted: Wed Feb 15, 2006 2:50 pm
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.

Posted: Wed Feb 15, 2006 3:07 pm
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.

Posted: Sun Feb 26, 2006 12:44 pm
by Xuri
*bump*
Anyone got a clue how this can be done? :P

Posted: Sun Feb 26, 2006 1:13 pm
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).