The Value Object
The Value Object is a simple object that for the most part functions behind the scenes. FS internally stores values in a Value Object. When you create, read or write values in your FS script a corresponding Value object is created for that value. In a FS script you will never interact directly with these objects. An author of a FS script will need no awareness of this internal object.
For the C# author, Value objects act as a wrapper for values within a FS script. He/She can create and manipulate these objects like any other C# object. When a FS Script creates a value to store, such as a string or an integer, FS creates a Value object to hold the scripts value and then stores the Value object into a collection class. When a FS script requires the value FS retrieves the Value Object for manipulation.
On the game developers side he/she can create Value objects, set their value and insert them into the collection. (VarCollection). For the FS script author these will be seen as preexisting variables. The game developer can update or change these dynamically therefor updating these values in the FS script.
An example could be the location of a mission waypoint. The mission author could pre load a set of coordinates or mission briefing for the FS script to interact with. To go one step further, in FS script you could author a mission by setting waypoints, briefings and objectives and load them at run time as needed. These would effectively enable modding capabilities. This model also allows you the game developer the ability to add content without re compiling or patching your unity project.
Freedom Script can store values as strings, integers or doubles.(floats). The Value Object has a contains and a type property.
As described previously, in C# Value Objects are stored in a collection class. They can be accessed in two ways. First is the preferred method. When a Subroutines “Execute” coded is triggered a reference to the VarCollection is passed to the function. This is identical to the way a C# event handles event arguments. The VarCollection is a typed collection of Value Objects
public override Value Execute(Value args, VarCollection vars)
<Review the Subroutine Class here>
In C# you now have access to all the script variables as C# Value Objects.
You can add, remove or update any one of the Value Objects. This is reflected back in the FS script. There are many support properties and methods to help you. Ex. Setvar,getVar..etc
The second path to changing FS script variables is directly from the interpreter object. It allows access to the same VarsCollection. The Interpreter object contains a property “vars”. The vars property returns the reference to this collection. Design considerations will dictate which method works best for your application. The best code reusability and portability will be to access this collection from the Subroutine Object.