Common Script Interface¶
Many WSF components use the WSF ‘common script interface’. An WSF component that uses the interface will accept:
Definitions of script variables: script_variables … end_script_variables
Definitions of scripts: script … end_script
Scripting system control commands (e.g., script_call_trace)
Common Scripts (defined below)
The WSF components that currently implement common script interface include:
The simulation.
The platform.
Some processors such as WSF_SCRIPT_PROCESSOR, and many others.
Some other platform parts, such as sensors.
Example:
processor my-script-proc WSF_SCRIPT_PROCESSOR
update_interval 10 sec
on_update
writeln("T=", TIME_NOW, " ", PLATFORM.Name(), " is updating");
end_on_update
end_processor
Predefined Variables¶
All components that use the Common Script Interface will have the following predefined variables as is appropriate for the component:
double TIME_NOW
The current simulation time in seconds. This is available to all scripts.
WsfPlatform PLATFORM
A reference to the platform. This is valid only within the platforms, sensors, and processors that implement the common script interface
Note
This is not available in simulation-level scripts.
WsfProcessor PROCESSOR
A reference to the processor. This is valid only in processors that use the common script interface (e.g., WSF_SCRIPT_PROCESSOR).
Note
This variable is not available in simulation-level or platform-level scripts
WsfSensor SENSOR
A reference to the sensor. This is valid within AFSIM’s predefined sensors, as well as any other sensors that use the common script interface.
Note
This variable is not available in simulation-level or platform-level scripts
WsfRandom RANDOM
A reference to the random number generator used by the simulation.
Note
Use of this object will affect the simulation’s random draws and therefore repeatability of simulation outcomes.
Common Scripts¶
Every WSF component that uses the common script interface will accept the following common scripts:
- execute at_time <time-value> [ absolute | relative ] …script body… end_execute¶
- execute at_interval_of <time-value> …script body… end_execute¶
These commands allow you define a script that is to execute once at a specific time or repeatedly at a specified time interval.
To execute a script at a specific time:
execute at_time <time-value> [ absolute | relative ] Script Body end_execute
If absolute is specified then the script will be executed at the specified simulation time.
If relative is specified then the script will be executed at the specified time relative to the creation time of the platform.
To execute a script repeatedly at a specified interval:
execute at_interval_of <time-value> Script Body end_execute
Note
If defined in the context of a processor, these scripts will execute even if the system is turned off as the purpose of the script may be to turn the system on!
- on_initialize …script_body… end_on_initialize¶
This command lets one define a script that is executed during phase 1 of platform initialization, if defined within the context of a platform, or during simulation initialization, if defined in the global script context.
During phase 1 initialization one may not assume anything about the state of the platform or any other platform component. If such a requirement is needed use the on_initialize2 script defined below.
on_initialize Script Body end_on_initialize
- on_initialize2 …script_body… end_on_initialize2¶
This command lets one define a script that is executed during phase 2 of platform initialization. Phase 2 initialization occurs when all platforms and their components (including those in the same platform context) have completed phase 1 initialization. Furthermore, phase 2 initialization at the platform context only occurs after phase 1 initialization at the global context.
Note
The on_initialize2 command is not available in the global (simulation-level) script context.
on_initialize2 Script Body end_on_initialize2
- on_update …script_body… end_on_update¶
This command lets one define a script that is executed whenever the platform or processor is updated. When specified within the context of a processor, the “update_interval’ command defines the interval at which the simulation invokes the “Update’ method.
Note
Use this with great caution at the platform level as it can have severe performance impacts. The on_update command is not available in the global (simulation-level) script context.
on_update Script Body end_on_update
Military Specific¶
An WSF component that uses the interface will accept:
Some weapons such as WSF_EXPLICIT_WEAPON.
Predefined Variables¶
WsfWeapon WEAPON
A reference to the weapon. This is valid only within weapons that use the common script interface (e.g., WSF_EXPLICIT_WEAPON).
Note
This variable is not available in simulation-level or platform-level scripts.