# Use triple quotes for multi line input or code segments that include quotes.
trick.add_read(2.0 , """
ball.obj.state.out.position[0] = 4.0
print "This is a quoted string inside the triple quotes"
"""
# Use a local python variable called read to get an appearance similar previous Trick input files
read = 4.0
trick.add_read(read , ... )
read += 0.2
trick.add_read(read , ... )
read = 5.0
trick.add_read(read , ... )
```
### Freeze the Simulation
To freeze a simulation call `trick.freeze([<freeze_time>])`. `trick.freeze()` called with no
arguments will freeze immediately. An optional freeze time may be provided to freeze some time
in the future.
```python
# Freezes immediately
trick.freeze()
# Freezes at an absolute time
trick.freeze(100.0)
# Freezes 5 seconds relative from the current sim_time
trick.freeze(trick.exec_get_sim_time() + 5.0)
```
### Checkpoint the Simulation
To checkpoint a simulation call `trick.checkpoint([<checkpoint_time>])`. `trick.checkpoint()` called with no
arguments will checkpoint immediately. An optional checkpoint time may be provided to checkpoint some time
in the future.
```python
# Checkpoints immediately
trick.checkpoint()
# Checkpoints at an absolute time
trick.checkpoint(100.0)
# Checkpoints 5 seconds relative from the current sim_time
trick.checkpoint(trick.exec_get_sim_time() + 5.0)
```
### Stopping the Simulation
To shutdown a simulation call trick.stop([<stop_time>]). trick.stop() called with no
arguments will shutdown immediately. An optional stop time may be provided to shutdown some time
in the future.
```python
# Stop immediately
trick.stop()
# Stop at an absolute time
trick.stop(100.0)
# Stop 5 seconds relative from the current sim_time
trick.stop(trick.exec_get_sim_time() + 5.0)
```
### Events and Malfunctions
Trick 10 events are a hybrid of Trick 07 events and malfunctions. A Trick 07 event has one or more conditions, one action, and is evaluated by the input processor. A Trick 07 malfunction also has one or more conditions (called triggers) that you can disable/enable, multiple actions, manual mode, and is evaluated before/after a specified job. Multiple conditions in malfunctions are ORed in 07, while multiple conditions in events can be specified by the user as being ORed or ANDed. Here is the Python syntax showing how Trick 10 events implement all of this functionality.
# Any combination of action(), action_job(), action_job_on(), or action_job_off() can be used for your malfunction action(s).
# NOTE: If the job is something you created just for use in malfunctions (e.g. it is not a scheduled job),
then it must be specified once and only once in the S_define file as a "malfunction" class job.
# Disable an action from being run (default is enabled)
<eventname>.action_disable(<index>) # the opposite would be <eventname>.action_enable(<index>)
# Manually fire the event once now, so that its actions will run once now
# (this event is now in "manual mode" and its conditions will not be evaluated until manual_done commanded)
<eventname>.manual_fire()
# Manually set an event as fired and hold on, so that its actions will run each cycle
# (this event is now in "manual mode" and its conditions will not be evaluated until manual_done commanded)
<eventname>.manual_on()
# Manually set an event as not fired, so that its actions will not run
# (this event is now in "manual mode" and its conditions will not be evaluated until manual_done commanded)
<eventname>.manual_off()
# Exit "manual mode" for this event and return to normal processing of its conditions
<eventname>.manual_done()
```
#### Setting variables synchronously: Real Time Variable Injector
You can also use `rti_add`/`rti_fire` commands in your event action syntax (or as standalone commands in the input file or
via the variable server) to set variables. See "Real Time Variable Injector".
#### Accessing the current Event state
```python
<eventname>.condtion_fired(<index>) # boolean: test if a particular event condition fired this cycle
<eventname>.condition_fired_count(<index>) # integer: number of times a particular event condition has fired
<eventname>.condtion_fired_time(<index>) # double: last sim time a particular event condition has fired
<eventname>.action_ran(<index>) # boolean: test if a particular event action ran this cycle
<eventname>.action_ran_count(<index>) # integer: number of times a particular event action has run
<eventname>.action_ran_time(<index>) # double: last sim time a particular event action has run
<eventname>.fired # boolean: test if the event conditions setup evaluated to true this cycle
<eventname>.fired_count # integer: number of times this event has fired
<eventname>.fired_time # double: last sim time this event has fired
<eventname>.ran # boolean: test if any event action ran this cycle
<eventname>.ran_count # integer: number of times this event has run an action
<eventname>.ran_time # double: last sim time this event has run an action
<eventname>.manual # boolean: test if this event is in "manual mode"
<eventname>.manual_fired # boolean: test if this event was fired manually this cycle
```
#### Event Example
Hopefully this example shows the various things you can do using events without being too confusing. Even the event components themselves can be queried and changed.
```python
# In this event example:
# evaluate velocity before integration...
# if it is over 50, print a message
# if it is over 100, reset the velocity to 0 after data recording is done for this frame
# if our sim has gone past 500 seconds, do not reset velocity when it goes over 100,
# but instead shutdown when velocity goes over 200