![]() |
VR-Forces 4.6.1 Class Documentation
|
The Add State Property example demonstrates the following:
The Add State Property example shows how to add new state properties to entities and how to update them in your code and Lua scripts. To add a new state property, you must first define it in the OPE file used by your entity. This example uses an example SMS called addStateProperty which can be found in data. This SMS includes a new OPE file called HumanWithAccuracyStats.ope. At the bottom of the file is defined the following:
(state-data (DtRwInt TargetsMissed 0 publish) (DtRwInt TargetsHit 0 publish) )
The state-data section defines the state properties which will be added to entities of this type. You can also add a parameter-data section to define parameter properties. The only difference between state and parameter properties is that parameter properties have static values whereas the values of state properties can change dynamically at run time.
There are four parts to the state property definitions.
To publish a property in DIS, you must be using the IEEE 1278.1-2012 version of the standard (DIS 7). State properties will be published as special Attribute records attached to the entity.
To publish a property in HLA, there must also be an object class attribute with the same name defined in your FOM. If the attribute is added in a custom subclass, you must also specify this using the hla-fom-class setting in the OPE. This example adds a new subclass called HumanWithAccuracyStats. Please see one of the included VrfStateProperty FDD files for an example of how these attributes are added.
(hla-fom-class "BaseEntity.PhysicalEntity.Lifeform.Human.HumanWithAccuracyStats")
The data type can be anything from a simple integer to a list of complex structures. Below is a list of acceptable data types. For further examples of how to define complex data types, refer to the Aggregate.ope file in the AggregateLevel SMS.
| Data Type | Description | HLA Representation/Encoding |
| DtRwInt | A 32 bit integer | RPRunsignedInteger32BE, HLAinteger32BE |
| DtRwReal | A 64 bit float | HLAfloat64BE |
| DtRwBoolean | A Boolean | RPRboolean |
| DtRwString | An ASCII string | RPRnullTerminatedArray of HLAASCIIchar |
| DtRwStructure | A fixed structure with multiple named fields | HLAfixedRecord with matching fields |
| DtRwList | A variable sized list of items | HLAvariableArray |
| DtRwMap | A variable sized map of items | HLAvariableArray of HLAfixedRecords, where the first field is the key |
The plugin code just consists of a single callback that listens for detonation interactions. When a detonation is received, if the shooter is local, the result of the detonation is checked and the TargetsHit or TargetsMissed property is updated accordingly.
The example scenario also includes a Lua scripted set called Clear Accuracy Stats that sets each of these properties back to 0.
In the Launcher:
To view the new behavior: