What is a ScriptObject?
A script object is basically an object that can store data, it's normally used in place of lots of global variables.
How to use a ScriptObject
To create the object all you need to do is:
Code:
new ScriptObject();
But that's not very useful!
How to make it useful you say?
Code:
new ScriptObject(MyScriptObject){
dynamicField = "Whatever";
};
MyScriptObject is the name of our ScriptObject, This is used for when we need to get information later on. It can be named anything, but if there is already and object with that name it will get overwritten. You do not need to give your ScriptObject a name.
dynamicField is the bit that stores the script objects data, it can be named anything and it's also legal to use arrays with it.
"Whatever" is whatever you want it to hold, it can hold anything, objects, vector, numbers strings. If you make it call something, eg myfunction(), it would store whatever that function returns, the " "'s are only necessary if the thing it's storing is a string.
How to get information from your ScriptObject
All you need is your ScriptObject's Name or Variable, that's if you assigned it one and the dynamic field that you want to get the data from.
Here are two examples:
Code:
%a = MyScriptObject.dynamicField;
//MyScriptObject is the name of our ScriptObject.
//dynamicField is the data we want to get from the ScriptObject.
Code:
%a = %scriptObject.dynamicField; //%scriptObject is our ScriptObject.
//dynamicField is the data we want to get from the ScriptObject
A few more things about ScriptObjects
You can assign ScriptObjects classes, these allow you to make functions without giving it a name:
Code:
new ScriptObject(){
class = MyScriptObject;
}; Script objects can have their own functions:
Code:
function MyScriptObject::function(%this, %var1, %var2, %var3){ //%this is the script object.
//whatever
} To make your own ScriptObject functions your ScriptObject needs to have a name or class. In this case MyScriptObject was the class of our ScriptObject.
ScriptObjects can be stored in variables local and global:
Code:
%ScriptObject = new ScriptObject();
$ScriptObject = new ScriptObject();
If the script object is outside of a function it will be created when that file is executed, if it's in a function it will be created whenever that function is called.
You can copy a script object:
Code:
new ScriptObject(MyScriptObject : CopyThis);
CopyThis is the name of the ScriptObject that we're copying.
Hope this helped 