The Add Script Variable example demonstrates the following:
- How to build a plugin module for the VR-Forces 3D Gui
- How to add a new scripted variable type to the script system
- How to reference this variable in a scripted task
Adding a New Lua Script Variable
The Add Script Variable example shows how to add a new scripted task or set variable to the script system, in this case an boolean list of values. It will show how to add the gui componenet as well as the component to transfer the data to/from reader/writer variables (which the foundation of getting this information into lua scripts).
How to Run the Example
Usage
Since this example is loaded as a plugin, it will need to be enabled in the Launcher. In the Launcher, click the Plug-ins button to bring up the Plug-ins Selection dialog. Enable the plugin.
To view the new behavior:
-
Start VR-Forces GUI and SIM.
-
Create a new Scenario - e.g. EntityLevel SMS on Ground_DB II terrain.
-
Create a new scripted task. Scripted tasks are accessed from the Simulation menu item - Simulation -> Scripts... Press New Script button within the Scripts dialog..
-
Add a new task parameter named "booleans" of 'Boolean List' scripted variable type.
-
Set a script Name and Edit the lua script for the scripted task
-
In the init method add lua code to loop over the table entries for the new 'Boolean List' variable and printWarn each entry.
myBools = {}
function init()
myBools = table.copy(taskParameters.booleans)
for index,value in pairs(myBools) do
printWarn(value)
end
vrf:setTickPeriod(0.5)
end
-
Press Add button within the Scripts dialog to add the new scripted task.
-
Close both the Edit script and the Scripts dialogs.
-
Create a new entity, bring up the entity information dialog and set the notify level to Warn.
-
Task the entity to perform the new scripted task and add a few boolean values to the 'Boolean List' task parameter.
-
The entity information dialog and the back-end console window should display the boolean values
Classes
| DtScriptedTaskRwBooleanListVariableConverter | The variable converter that converts to/from scripted task variable. |
Plugin Entry Points
extern "C" {
{
info.
pluginDescription =
"Back-end plugin addition to add new boolean list script variable";
}
{
return true;
}
}