System Library

From MyGamingTalk
Jump to navigation Jump to search
Script Reference System Library

Global FileSystem Functions


FileDelete

Deletes a file by name. This function is restricted to files under the user folder.

Parameters: (filename)

Returns: true if success, false if failed

Example:

 FileDelete("myfile.txt");

FileEnumerate

Enumerates over all files in a directory. This function is restricted to files under the user folder. This function will call the provided script function with all files enumerated.

Parameters: (folder name, script function)

Returns: true if success, false if failed

Example:

 myfunc = function(filename)
 {
 }
 FileEnumerate("myfolder", myfunc);

FileExists

Checks if a file exists by name. This function is restricted to files under the user folder.

Parameters: (filename)

Returns: true if exists, false if not

Example:

 if(FileExists("myfile.txt"))
 {
 }

Newline

Returns a NewLine custom type. Used for writing newlines in text formatted files. It was a function in Omni-bot 0.71, but now it is a variable in Omni-bot 0.8.

Parameters: none

Returns: none

Example:

 f = File();
 f.Open("myfile.txt", "text", false);
 if(f.IsOpen())
 {
     f.Write("Some test data", System.NewLine);
 }
 f.Close();

File

Creates a new File Object.

Parameters: none

Returns: none

Example:

 f = File();

Close

Closes the file object and commits changes to disk.

Parameters: none

Returns: none

Example:

 f.Close();

EndOfFile

Checks if the File Object is at the end of the file. Useful for read operations.

Parameters: none

Returns: true if end of file, false if not.

Example:

 eof = f.EndOfFile();

FileSize

Gets the file size of the file, in bytes.

Parameters: none

Returns: size of file in bytes

Example:

 size = f.FileSize();

Flush

Flushes the file buffer to disk.

Parameters: none

Returns: none

Example:

 f.Flush();

IsOpen

Checks if the file is currently open. Usually used after a call to Open.

Parameters: none

Returns: true if file is open, false if not

Example:

 if(f.IsOpen())
 {
 }

Open

Creates a new File Object.

Parameters: (filename, "text"/"binary", readonly<optional>, append<optional>)

Returns: true if success, false if failed.

Example:

 if(f.Open("myfile.txt", "text", false))
 {
 }

ReadFloat

Reads a float from the file.

Parameters: none

Returns: float read, or null if there was an error

Example:

 num = f.ReadFloat();

ReadInt

Reads an integer from the file.

Parameters: none

Returns: integer read, or null if there was an error

Example:

 num = f.ReadInt();

ReadLine

Reads a string from a file until a newline or end of file is encountered.

Parameters: none

Returns: string read, or null if there was an error

Example:

 str = f.ReadLine();

ReadString

Reads a string from a file.

Parameters: none

Returns: string read, or null if there was an error

Example:

 str = f.ReadString();

Seek

Seeks the read/write position to a specified offset.

Parameters: (byte offset to seek to)

Returns: none

Example:

 f.Seek(100); // seek 100 bytes into file

Tell

Returns the current offset of the read/write position in the file.

Parameters: none

Returns: byte position in file

Example:

 t = f.Tell();

Write

Writes a value of varying types to the file, in whatever file mode was used to open the file.

Parameters: (...)

This function can take any number of parameters, of types integer, float, string, or NewLine;

Returns: none

Example:

 f = File();
 f.Open("myfile.txt", "text", false);
 if(f.IsOpen())
 {
     f.Write("Some test data", System.NewLine);
 }
 f.Close();