# UOX3 Script Engine

### Functions, Methods, Properties and Event handling

### File I/O Methods

Open
Prototype |
    Open( string filename, string accessMethod );
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).
Example of Usage |
    var mFile = new UOXCFile;
    mFile.Open( "test.dat", "a" );

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.

Free
Prototype |
    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();

## File I/O Properties

Property | Purpose
--- | ---
pos (read/write) | The current position that you are at in the file. This property can be read and set, where setting it moves relative to the start of file (ie 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.
length (read) | The length of the file
eof (read) | A boolean value returning true if the file pointer is at the end of the file.

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