Predefined functions
loadFile
The loadFile
function allows you to read the contents of a text file and store it as a string variable. To use it, simply provide the file path as an argument, like this:
var myList = loadFile("mylist.txt")
The syntax is:
loadFile(filePath)
Here, filePath
is the path to the text file, relative to the rules
sub-folder of your project.
Tip
When dealing with larger files, such as long lists, it is recommended that you call loadFile
inside the initialize
function, which is executed only once when the engine starts up. This can help improve performance and avoid potential memory issues.
CLONE
The CLONE
function performs a deep copy of an array or object; making it useful for scenarios where you don't want to reference the original data but instead make a separate copy of it.
This function is also used in domain manipulations.
To use the function, pass the variable name as an argument.
CLONE(variableName)
For example:
var object = {
name: "foo",
data: {
subArray: [0, 1, 2]
}
}
var myCopy = CLONE(object);
myCopy.name = "fighters";
CONSOLE.log(JSON.stringify(object));
CONSOLE.log(JSON.stringify(myCopy));
In this example, the printed output shows that modifying the myCopy
object has no impact on the original object.