Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

Properties persistent between sessions

From FlightGear wiki
Jump to: navigation, search

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

Source code