Nasal scripting language

From FlightGear wiki
Revision as of 23:56, 23 June 2006 by Sek (talk | contribs) (Added listeners)
Jump to navigation Jump to search

Many applications today support scripting as a means of "gluing" the application together and enabling users to extend functionality of the application. For example, the 3d modeling application Blender implements most of its import and export filters as user contributed Python scripts, which are automatically integrated into the menu system. Many games are also integrating a scripting language to make it easier for modders to add features.

FlightGear has a scripting language called NASAL. You can find out more about it at the NASAL website.

http://www.plausible.org/nasal

Elements of the graphical user interface, aircraft instruments and performance can be scripted.

NASAL Scripting for Flight Gear

Listeners

Listeners

A listener specifies a function to be executed when a specified property is written to. The value may or may not change, so the listener may execute "on change" if the property value changes, but also if it is rewritten with the same value. The listener executes whenever the property is written to.

A listener is attaches to a property. Listeners do not work with "tied" properties (most are in the FDM, but you can spot them by Ctrl-clicking "." in the property browser).

Setting a listener:

monitor_course = func {
  print("Monitoring course.");
}
setlistener("instrumentation/gps/wp/leg-course-deviation-deg", monitor_course);

Deleting a listener:

removelistener(monitor_course);

Returning from a listener early:

monitor_course = func {
  if( getprop(Internal, "power-good") == "off" ) {
     return 0;
  }
  print("Monitoring course."); 
}

Examples:

TODO


Tips

How to play sounds using NASAL script?

The same way one would do animations using Nasal;

Adjust properties in Nasal (they may be "private" properties in your own subtree of the property list, say /tmp/<aircraft>) and let the sound configuration file act on those properties. (from flightgear-devel)