duyminh1998 / pycmo

Command Modern Operations Learning Environment
Other
49 stars 23 forks source link

Time compression is not set properly upon scenario restart #25

Closed duyminh1998 closed 9 months ago

duyminh1998 commented 10 months ago

Summary

Sometimes when we restart the scenario through pyCMO, the time compression is not correctly set, or it resets to x1 time

Steps to reproduce

  1. Run the floridistan/restart_demo.py script and notice that sometimes when the scenario restarts and loads, the time compression is reset to x1 instead of the correct x15.

What is the current bug behavior?

The time compression is reset after the scenario restarts and loads

What is the expected correct behavior?

The time compression is correctly set to whatever was specified in the Export observation initially event in the game when the scenario restarts and loads.

Relevant logs and/or screenshots

duyminh1998 commented 10 months ago

Two possible causes:

  1. The game is not firing the VP_SetTimeCompression(...) line in the Export observation initially event.
  2. Our scripts are triggering some hotkey combination that is resetting the time compression.
duyminh1998 commented 10 months ago

It seems likely that our Export observation initially event is not firing upon scenario load (or it is not firing consistently). This is because we also observe that we are not correctly writing out that the scenario has not ended (it has been restarted).

duyminh1998 commented 9 months ago

If the Export observation initially event sometimes does not fire, then there are two potential solutions:

  1. Add an extra event that fires 1 second into the scenario to run the Export observation initially action again.
  2. Detect that the time compression is wrong or the scenario end status is not correctly recorded, then pause the game and let the environment restart the scenario to hopefully fix the problem. This is the current default behavior but it does not totally work because while we are in the process of restarting, the scenario is still running which messes with our button presses.
duyminh1998 commented 9 months ago

Can be tested by modifying the Export observation initially action in-game with the lines

ScenEdit_RunScript('pycmo_lib.lua', true)
ScenEdit_ExportScenarioToXML()
if math.random() > 0.3 then
  VP_SetTimeCompression(3)
  ScenarioHasEnded(false)
end

to simulate the scenario sometimes not loading properly

duyminh1998 commented 9 months ago

Potential bug noticed while testing: If the *_scen_has_ended.inst file does not have the entry "Comments": "true" when we restart the scenario and we do not load the scenario properly (i.e. the Export observation initially event does not fire), then we will run into a bug where the environment thinks that everything is okay and will proceed to run. This is because the way we check that the scenario has not loaded properly is by checking whether "Comments": "false" exists in the *_scen_has_ended.inst file after we restart. This is because we only record "Comments": "true" in the *_scen_has_ended.inst file when we end the scenario. Solutions are to record this scenario at the beginning of a run, or to make the check for the scenario not loading properly more comprehensive (e.g. check that the time compression is also not set properly).