# UOX3 Script Engine

### Functions, Methods, Properties and Event handling

### File I/O Methods

Open
Prototype |
    Open( string filename, string accessMethod, string subFolder );
Purpose | Opens a file for reading, writing or appending.
Notes | accessMethod is a one byte string, which contains either "a" (append), "r" (read) or "w" (write). Subfolder is a subfolder under UOX3/shared/, which will be created if it doesn't exist.
Example of Usage |
    var mFile = new UOXCFile;
    mFile.Open( "test.dat", "a", "subFolder" );

Close
Prototype |
    Close();
Purpose | Closes a file that is currently open.
Notes | Closing an unopened file is undefined.
Example of Usage |
    mFile.Close();

Write
Prototype |
    Write( string toWrite );
Purpose | Writes a string out to the file.
Notes | A file cannot be longer than 1MB in size. If opened for reading, this will not work.
Example of Usage |
    mFile.Write( "Hello cruel world\n" );

Read
Prototype |
    string Read( int numBytes );
Purpose | Returns a string of length numBytes, reading numBytes from the opened file.
Notes | numBytes must be at least 1 and less than or equal to 512.
Example of Usage |
    var mLine = mFile.Read( 80 );

ReadUntil
Prototype |
    string ReadUntil( string delimeter );
Purpose | Reads a string until it encounters a newline or the string specified by delimeter.
Notes | delimiter is at most a 2 character string (for C style character escapes, where \n is a newline, \' is a quote and so on). Will not read more than 512 bytes.
Example of Usage |
    var untilT = mFile.ReadUntil( "t" );
     // reads a line until it hits the letter t, a newline, or 512 bytes in length.

Length
Prototype |
    int Length();
Purpose | Returns the length of the file
Example of Usage |
    var fileLength = mFile.Length();

Pos
Prototype |
    int Pos();
Purpose | Returns or sets the position we are at in the file
Notes | The current position that you are at in the file. This can be read and set, where setting it moves relative to the start of file (i.e. if you set it to 5, it would be 5 bytes from the start, not 5 bytes from it's current location). You cannot seek a location if you have opened the file for append.
Example of Usage |
    var filePos = mFile.Pos();

EOF
Prototype |
    bool EOF();
Purpose | A boolean value returning true if the file pointer is at the end of the file.
Example of Usage |
    while( !mFileRead.EOF() ) { ... }

Free
Prototype |
    bool Free()
Purpose | Deallocates the memory associated with creating the variable.
Notes | This must be called otherwise a slow memory leak will occur.
Example of Usage |
    mFile.Free();

DeleteFile
Prototype |
    bool DeleteFile( fileName(, subFolderName ))
Purpose | Deletes a specified file, either in root of shared folder, or inside a subfolder.
Notes | File and subfolder names cannot contain some characters such as forward or backwards slashes, double dots, etc.
Example of Usage |
    var fileName = "myFile.jsdata";
    var folderName = "mySubFolder";
    DeleteFile( fileName, folderName );

©Copyright 2000-2001 WWW.UOX3.NET (Daniel Stratton/Matthew Randall)