API Question Accessing Scenario from oapi::Module

meson800

Addon Developer
Addon Developer
Donator
Joined
Aug 6, 2011
Messages
405
Reaction score
2
Points
18
For an Orbiter module I am working on, I need my module to be able to read certain values into a scenario file before SimulationStart(or right after it), and write those values at SimulationEnd (or right after it).

For a MFD, the functions ReadStatus and WriteStatus are called.

For a VESSEL2, the functions clbkSaveState and clbkLoadStateEx are called.

Both of the above return a FILEHANDLE to the scenario; however, I did not find anything comparable to this in the Module class.

At first, I thought that if I could get the filename of the scenario loaded, I could just directly read/write to the scenario file, but there appears to be no API function to get the filename of a loaded scenario.

In this case, saving is not a real issue; I could always just save into (Current State).scn (although this would not save the status values into quicksaves). Without an API function, I would have to ask the user to input the filename of the scenario they just loaded. Although this is possible, it seems...inelegant.

Is there a better solution?

Thanks! :tiphat:
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,390
Reaction score
577
Points
153
Location
Vienna
If there really is no API function to get the scenario file currently loaded, I guess you can only revert to hacking to get a more "elegant" solution.

I'd do it similarly to OMP's scenario selector: find Orbiter's main window, find the scenario selection window, get the currently selected item, get the window text of it, feed the result into oapiOpenFile to get a FILEHANDLE. Or simply open it as usual...

I think this is the least intrusive method to find it.

On a side note: the reason why only MFD and VESSEL2 gets a load/save callback is IMHO the focus: for MFD and VESSEL2 you get only that part of the file that belongs to your MFD/VESSEL instance. For a module, the FILEHANDLE architecture (ReadScenario_next, Read/WriteItem etc.) is not so good, as there is no obvious way to scan for sections like in e.g. INI files.

---------- Post added at 23:52 ---------- Previous post was at 23:38 ----------

BTW: A quick search for "FILEHANDLE" revealed that the question has been asked before, although with a different goal.
 
Last edited:

orb

O-F Administrator,
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
For what you want to do you only need to export opcLoadState and opcSaveState from your DLL without additional hacks.
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,390
Reaction score
577
Points
153
Location
Vienna
For what you want to do you only need to export opcLoadState and opcSaveState from your DLL without additional hacks.

Is this still in? It is not documented AFAIK.
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,390
Reaction score
577
Points
153
Location
Vienna
(emphasis mine)
opcLoadState is only called for a plugin module if a block with the module name is present in the scenario file.

That would mean that the OP would need an appropriate block in his scenario to get the callback triggered. Would opcSaveState write this block, if not present? Is there a signature documentation for these functions?
 

meson800

Addon Developer
Addon Developer
Donator
Joined
Aug 6, 2011
Messages
405
Reaction score
2
Points
18
Thank you, I will use the opcLoadState and opcSaveState method.

Sorry about reposting, I did search before posting and came across this result, but I was unsure if it still existed in the API. (For some reason, I missed how recent that thread was). My initial testing showed that opcLoadState was not called, so I assumed that the function no longer existed. However, I see that it failed because of
opcLoadState is only called for a plugin module if a block with the module name is present in the scenario file.

Thanks!:tiphat:
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,390
Reaction score
577
Points
153
Location
Vienna
Sorry about reposting, I did search before posting and came across this result, but I was unsure if it still existed in the API.

And there is the signature documented as well:
Code:
DLLCLBK void opcSaveState (FILEHANDLE scn) {}

DLLCLBK void opcLoadState (FILEHANDLE scn) {}
At least we have it all bundled and linked in one thread now ;) .
 
Top