Properties persistent between sessions: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(+rel: Aircraft-set.xml, $FG_HOME, FlightGear configuration via XML)
(→‎Aircraft: Added pure nasal example)
Line 44: Line 44:
   </MyModule>
   </MyModule>
  </nasal>
  </nasal>
</syntaxhighlight>
And yet another way to do this entirely in Nasal is:
Run this nasal code once:
<syntaxhighlight lang="nasal">
aircraft.data.add("sim/bla1", "sim/bla2");
aircraft.data.save();
</syntaxhighlight>
Then the properties are saved when that code is run, and also at every reinit and exit.
If you want it to be saved every 30 seconds in addition to the above, then you change the last line to:
<syntaxhighlight lang="nasal">
aircraft.data.save(0.5);
</syntaxhighlight>
Now to make sure the properties are also read at the startup, modify the xml declarations of the properties to read something like this:
<syntaxhighlight lang="xml">
<bla1 userarchive="y" type="bool">true</bla1>
<bla2 userarchive="y" type="int">56</bla2>
</syntaxhighlight>
</syntaxhighlight>



Revision as of 21:23, 29 November 2015

Sometimes you would want to have some properties persistent between sessions. It could for example be to save the state of a dialogue or to have an aircraft start up in the same state as you left it.

Preferences and GUI

To make preferences and GUI properties persistent between FlightGear sessions, use the userarchive attribute:

 <?xml version="1.0" encoding="UTF-8"?>
 <PropertyList>
  <foo userarchive="y">Hello</foo> 
 </PropertyList>

Aircraft

To make aircraft properties persistent between FlightGear sessions, add this to the aircrafts -set.xml file:

 <sim>
  <!-- ... -->

  <aircraft-data>
   <path>/controls/flight/flaps</path>
   <path>/controls/lighting/nav</path>
  </aircraft-data>
 </sim>

Another way to do this if you are more into Nasal than XML would be to instead add this to the aircrafts -set.xml file:

 <nasal>
  <!-- ... -->

  <MyModule>
   <script><![CDATA[
    aircraft.data.add(
     "/controls/flight/flaps",
     "/controls/lighting/nav",
    );
   ]]></script>
  </MyModule>
 </nasal>

And yet another way to do this entirely in Nasal is:

Run this nasal code once:

aircraft.data.add("sim/bla1", "sim/bla2");
aircraft.data.save();

Then the properties are saved when that code is run, and also at every reinit and exit.

If you want it to be saved every 30 seconds in addition to the above, then you change the last line to:

aircraft.data.save(0.5);

Now to make sure the properties are also read at the startup, modify the xml declarations of the properties to read something like this:

<bla1 userarchive="y" type="bool">true</bla1>
<bla2 userarchive="y" type="int">56</bla2>

Related content

Wiki articles

Mailing list threads