<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.flightgear.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Moksha</id>
	<title>FlightGear wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.flightgear.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Moksha"/>
	<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/Special:Contributions/Moksha"/>
	<updated>2026-04-03T19:29:56Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.6</generator>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Howto:Install_aircraft&amp;diff=59263</id>
		<title>Howto:Install aircraft</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Howto:Install_aircraft&amp;diff=59263"/>
		<updated>2013-03-31T03:18:04Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Choosing aircraft */ remove = symbol&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{installing}}&lt;br /&gt;
The latest official [[aircraft]] can be downloaded at [http://www.flightgear.org/download/aircraft-2-10-filterable/ FlightGear.org Aircraft], which then usually require unzipping software to extract from a compressed file format. Then these must be manually installed in a FlightGear software installation to use. The details depend on the method of download, operating system, and user setup. &lt;br /&gt;
&lt;br /&gt;
An open source file archiver is [http://www.7-zip.org/ 7-Zip], although be aware of user setup.&lt;br /&gt;
&lt;br /&gt;
You may also want to take a look at:&lt;br /&gt;
* [[Aircraft]]&lt;br /&gt;
* [[Helicopter]]&lt;br /&gt;
* [[Vehicle]]&lt;br /&gt;
* [[Table of models]]&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
(Ubuntu 7.10) &lt;br /&gt;
# Download the aircraft&lt;br /&gt;
# Open Terminal and log in as root&lt;br /&gt;
# Navigate to /usr/share/Games/FlightGear/Aircraft&lt;br /&gt;
# Extract your aircraft file into the folder&lt;br /&gt;
# Start up flight gear. Your aircraft should show up in the launcher&lt;br /&gt;
&lt;br /&gt;
=== Macintosh OS X ===&lt;br /&gt;
&lt;br /&gt;
# Open GUI Launcher for FlightGear Mac&lt;br /&gt;
# Click on &amp;quot;Others&amp;quot; tab at middle right of launcher&lt;br /&gt;
# Click &amp;quot;Install Add-On Data&amp;quot; link at bottom of launcher&lt;br /&gt;
# Select aircraft folder from menu, and click &amp;quot;Open&amp;quot;&lt;br /&gt;
# Click OK on pop-up box.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
# Download an aircraft and save it on your desktop.&lt;br /&gt;
# Unzip the file, using a file archiver like 7-Zip.&lt;br /&gt;
# Move the unzipped folder (usually the aircraft's name) to your &amp;lt;tt&amp;gt;FlightGear/data/Aircraft&amp;lt;/tt&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
'''!!! IMPORTANT !!!'''&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Modern&amp;quot; Windows Versions (e.g. XP, Vista, Win7) tinkering a lot with user rights on access level. Therefore it's a bad idea to install and run FlightGear to and from &amp;quot;C:\Program Files&amp;quot; (German: C:\Programme). Find another drive / folder where you as logged in user have all neccesary right to read, write and execute the files you installed. Additionally there's a space / blank in folder's name which could cause weird behaviour. Use something like &amp;quot;C:\FlightGear&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Choosing aircraft ==&lt;br /&gt;
If you are looking for information to decide what aircraft to download, try [[Table of models]] or [[Aircraft]]. External links to third party aircraft can be found at [[FlightGear hangars]]. Remember that the latest aircraft may not load with previous versions, so look for older aircraft in the links section.&lt;br /&gt;
&lt;br /&gt;
== For developers ==&lt;br /&gt;
Help develop the [[FlightGear Package Manager]] which is intended to support automatic aircraft and scenery installation, currently in alpha development and in need of testing.&lt;br /&gt;
&lt;br /&gt;
== Related content ==&lt;br /&gt;
* [[Installing Scenery]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Howto_Installer_un_avion]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Nasal_scripting_language&amp;diff=38416</id>
		<title>Nasal scripting language</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Nasal_scripting_language&amp;diff=38416"/>
		<updated>2011-12-25T05:43:02Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Garbage collection */ sentence improvement&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''Please note that a considerable amount of resources has not yet been incorporated here, you can check these out by going to the &amp;quot;[[Talk:Nasal_scripting_language|discussion]]&amp;quot; page, where we are collecting links to webpages and mailing list discussions/postings related to Nasal.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nasal = Not another scripting language!==&lt;br /&gt;
&lt;br /&gt;
 The short summary is that Nasal is a scripting language that is tightly integrated with FlightGear itself, &lt;br /&gt;
 and provides a very easy way to manipulate the property tree, which is the core data structure within the &lt;br /&gt;
 simulator that exposes all the important internal runtime states of FlightGear. &lt;br /&gt;
&lt;br /&gt;
[[FlightGear]] offers a very powerful functional scripting language called [http://plausible.org/nasal/ &amp;quot;Nasal&amp;quot;], which supports reading and writing of internal [[Property Tree Intro|FlightGear properties]], accessing internal data via extension functions, creating GUI dialogs and much more. &lt;br /&gt;
&lt;br /&gt;
Nasal uses some of the concepts of ECMA/JavaScript, Python and Perl and implements a simple but complete way of Object Oriented Programming (OOP), Nasal uses an internal garbage collector so that no manual memory management is required by the programmer. &lt;br /&gt;
&lt;br /&gt;
People familiar with other programming languages, and scripting languages like JavaScript in particular, are usually able to learn Nasal rather quickly. FlightGear provides a rich library of simulation-specific and general-purpose functions that can be accessed by Nasal scripts.&lt;br /&gt;
&lt;br /&gt;
Nasal code can be run by aircraft configuration files, and it can be embedded in various [[XML]] files (dialog files, animation files, bindings for joysticks, keyboard and cockpit controls, and even in [[Howto: Nasal in scenery object XML files|scenery objects]]). Nasal is platform independent and designed to be thread safe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Some success stories ===&lt;br /&gt;
These were taken from the developers mailing list:&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Nasal is *very* well designed, compact, and efficient.  It is used heavily throughout many areas of FlightGear.&amp;quot;&lt;br /&gt;
* &amp;quot;It's interesting though how much nasal you can actually get away with using without making a blip on frame rates.  Nasal is *very* efficient and powerful for being an interpreted script language.&amp;quot;&lt;br /&gt;
* &amp;quot;FlightGear needed a built-in scripting language, and it has one. A compact, clean, elegant and fast one, Nasal extension functions interface perfectly to the property tree, the event manager, the built-in XML parser etc. Nasal is very tightly integrated in fgfs and used all over the place.&amp;quot;&lt;br /&gt;
* &amp;quot;There's no question that scripting languages are good; fgfs has a lot of Nasal code now. In my profiling I have never seen the nasal interpreter as a hot spot&amp;quot;&lt;br /&gt;
* &amp;quot;I'm a simple content contributor with very little background in programming. When I made my first Aircraft (the bf109) I was confronted with the need to deploy slats automatically at a given speed. I din't want to embed C++ code or had such a complex script that the error messages in FG wouldn't help me and I previously only used a bit of python. I looked at some Nasal scripts and within a few hours it worked. I was impressed how easy it is to write even complex Nasal scripts. Later I started developing the walker feature that made it possible to walk around in the scenery, all with nasal. Stuart kindly enhanced the walker and added an animation system to it (see bluebird), again with nasal. Others have made Flight computers with it (see V-22 and Su-37). Nasal is a worthy tool&amp;quot;&lt;br /&gt;
* &amp;quot;I used Nasal to build several rather complex systems, like Fuel System, Stab Augmentation System, Autopilot Logic, Terrain Avoidance Radar, Radar Warning Receiver and much more, and yes, I love Nasal too. Learning Nasal use was easy and fun and I din't found any limitation yet.&amp;quot;&lt;br /&gt;
* There are many vital parts of FlightGear currently coded in nasal.  There are also random bits of nasal code scattered around in joystick configurations, instrument and aircraft models, scenery models...  everywhere.&lt;br /&gt;
* &amp;quot;We have an entire directory full of Nasal 'function' libraries now, and I'm quite happy using them instead of rolling my own duplicate functionality.&amp;quot;&lt;br /&gt;
* Nearly every sophisticated Aircraft uses some kind of Nasal, be it Effects like tyre smoke or important functionalities like Engine and electric management, The Bluebird FDM is completely written in Nasal, vital parts of the V-22 Osprey rely on it, Flyby and Model View wouldn't work anymore, no more interactive objects in the scenery, lots of the MP System would be gone, ... Nasal is THE tool which makes FG development fun and adds nearly unlimited possibilities.  If you need an example, look at the Bluebird animated walker, all done in Nasal.&amp;quot;&lt;br /&gt;
* &amp;quot;there are good reasons to use Nasal - first of all the user base which regularly compiles their own code is small, whereas people do install addon packages - so I get a lot more feedback and test results. Second that one usually can't really crash the whole system from Nasal. Third, it's very easy to quickly try something and very maintenance-friendly. Fourth, you can actually start developing something without knowing how the core code ties together - which I suppose takes a lot of time to learn.  And so on.&amp;quot;&lt;br /&gt;
* &amp;quot;Hard-coding every instrument in C++ instead of nasal means only developers following/building the latest cvs  head code get to use whatever until the next release cycle.&amp;quot;&lt;br /&gt;
* &amp;quot;Hard coding every instrument/flight control in C++ means my WW-II storch (et.al.) is stuck with an autobrake functionality it doesn't have nor need.&amp;quot;&lt;br /&gt;
* &amp;quot;I think it boils down to the fact that we have two approaches that can accomplish the same thing.  The C/C++ approach offers high performance but there is a dependence on when the C/C++ code was added to FlightGear.  The Nasal approach offers fast prototyping, flexibility, and more (but not complete) independence from the C/C++ code.&amp;quot;&lt;br /&gt;
* &amp;quot;A basic problem with C++ functions is it is hard/impossible to override them for a special purpose. Writing in pure nasal allows function name hijacking and other tricks that can't be used on C++ code.&amp;quot;&lt;br /&gt;
* &amp;quot;Given the fact that FG is platform independent, I don't know if the embedded C++ is doing the same on Windows, Linux, PPC and intel Macs. Apart from the fact that if I was able to code c++ I would embed it to FG rather than in an Aircraft specific script&amp;quot;&lt;br /&gt;
* &amp;quot;If we ported Nasal code over to C++ we'd lose the ability to change small things &amp;quot;on the fly&amp;quot; without compiling over and over again. We'd also lose good programmers, who prefer scripting over C++. Aircraft creation would not be customizable etc etc.&amp;quot;&lt;br /&gt;
* &amp;quot;The argument against Nasal is essentially that C++ is faster than Nasal - which, everything else being equal, is certainly correct. But highly specialized Nasal code written for a particular problem outperforms general  purpose C++ code - I've given several examples in the past. If someone were e.g. to add movement to Nasal spawned models by adding a velocity property, I'm not sure it would outperform my Nasal quadtree-sorted adaptive range code which priorizes movement for things actually inside the field of view. Of course, if you'd hard-code that specialized algorithm, it would be faster than the Nasal version - but then you couldn't apply it to other problems any more.&amp;quot;&lt;br /&gt;
* &amp;quot;How many airplane developer will you loose if you remove the Nasal engine from FGFS because they can write Nasal code but not C++ code?&amp;quot;&lt;br /&gt;
* &amp;quot;The algorithm being equal, I don't think there's a question that C++ is faster (I doubt the factor 10 though - that seems to be an extreme case). Everything else being equal, I also don't think there's a question that Nasal code is more accessible. And I would base any decision what to hard-code and what not on that balance.&amp;quot;&lt;br /&gt;
* &amp;quot;Nasal is just much better suited for FlightGear than many alternatives because of it's size, processing speed and because a number of FlightGear core developers have a good idea what's going on.&amp;quot;&lt;br /&gt;
* &amp;quot;In theory we could even use VBScript but Nasal has proven to be valuable for almost 10 years, so no reason to change or add another scripting language. Besides, if you know JavaScript then learning Nasal would take little effort.&amp;quot;&lt;br /&gt;
* &amp;quot;The pool of people with commit rights to the core C++ code is very, very small.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nasal really is an excellent choice for prototyping and implementing new features and even completely new systems in FlightGear. &lt;br /&gt;
&lt;br /&gt;
For example, the [[bombable]] script implements &amp;quot;dog fighting&amp;quot; support on top of FlightGear, without ANY changes to the C++ side of the code, just by using some fairly advanced scripted code (implemented in the built-in Nasal programming language). You can basically imagine it like a &amp;quot;MOD&amp;quot; of FlightGear. In other words, the bombable script creates a completely new &amp;quot;mode&amp;quot; in FlightGear.&lt;br /&gt;
&lt;br /&gt;
No matter if it's scenery, aircraft, AI scenarios or whatever: many things that were originally never planned to be supported by FlightGear core developers, are now implicitly supported because of the loose coupling between highly configurable and flexible systems, such as the property tree and the Nasal scripting language.&lt;br /&gt;
&lt;br /&gt;
So we are really standing on the shoulders of giants here, because we are now -after 10+ years- in the position to create significant new features (and even completely new systems in FlightGear) within the constraints of the FlightGear base package, without even touching the C++ source code at all - simply because FlightGear has become so flexible and extensible.&lt;br /&gt;
&lt;br /&gt;
All of this became possible by some important architectural decisions, such as for example the use of XML and plain text files for pretty much all configuration files in FlightGear (and thus open file formats in general), a publicly accessible tree of state variables that can be easily inspected and modified at runtime (the property tree). Similarly, the decision to embed a scripting language that can be used for scripting the entire simulator was another important decision.&lt;br /&gt;
&lt;br /&gt;
In FlightGear, Nasal is the most accessible method of customizing the whole simulator to a very high degree. Nasal code can be easily edited using a conventional text editor, there are no special tools required: Nasal source code is interpreted, compiled to bytecode and run by the Nasal &amp;quot;virtual machine&amp;quot; using FlightGear itself. &lt;br /&gt;
&lt;br /&gt;
The emerging [[A local weather system|Local weather]] system was entirely prototyped in Nasal space, and is now being increasingly augmented by moving performance-critical functions to C++ space instead.&lt;br /&gt;
&lt;br /&gt;
Using Nasal, it is even possible to create entirely scripted flights and smart &amp;quot;AI bots&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 I have something here that I think is kind of fun.  I've been fiddling with&lt;br /&gt;
 this off and on since last fall and decided it was time to clean it up a bit&lt;br /&gt;
 and quit hording all the fun for myself.  Basically I have taken the F-14b&lt;br /&gt;
 and created a high performance Navy &amp;quot;drone&amp;quot; out of it.  It can auto-launch&lt;br /&gt;
 from a carrier, auto fly a route (if you've input one) and can do circle&lt;br /&gt;
 holds (compensating for wind.)  I've added a simulated&lt;br /&gt;
 gyro stabilized camera that will point at anything you click on and then&lt;br /&gt;
 hold that view steady no matter what the airplane does (similar to what real&lt;br /&gt;
 uav's can do.)  Finally, you can command it to return home and it will find&lt;br /&gt;
 the carrier, setup a reasonable approach and nail the landing perfectly&lt;br /&gt;
 every time (factoring in wind, carrier speed, etc.): http://www.flightgear.org/uas-demo/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As of 03/2009, there were approximately 170.000 lines of reported Nasal source code in the FlightGear base package [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg21333.html], compared to 2006 this is almost a rate of growth of 600% within 3 years [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg01728.html]. This illustrates the sheer adoption rate Nasal is experiencing in FlightGear.&lt;br /&gt;
&lt;br /&gt;
(As of 10/2011, the FlightGear base package contained 326.000 lines of Nasal source code in *.nas files)&lt;br /&gt;
&lt;br /&gt;
Note that this page is mostly about FlightGear-specific APIs/extension functions and usage patterns. &lt;br /&gt;
Thus, you may also want to have a look here:&lt;br /&gt;
&lt;br /&gt;
* [http://plausible.org/nasal/lib.html core language/library documentation] &lt;br /&gt;
* [http://plausible.org/nasal/sample.nas annotated source code examples]&lt;br /&gt;
* [http://plausible.org/nasal/doc.html Nasal design document]&lt;br /&gt;
* [http://www.plausible.org/nasal/flightgear.html a helpful tutorial about using Nasal in FlightGear].&lt;br /&gt;
&lt;br /&gt;
In addition, the [http://gitorious.org/fg/fgdata/trees/master/Nasal Nasal directory] in the FlightGear base package contains a wealth of tested, proven and usually well-commented source code that you may want to check out for additional examples of using the Nasal scripting language in FlightGear [http://gitorious.org/fg/fgdata/trees/master/Nasal].&lt;br /&gt;
&lt;br /&gt;
If you have any Nasal specific questions, you will want to check out the [[Nasal FAQ]], feel free to ask new questions or help answer or refine existing ones. If you would like to learn more about existing Nasal modules in FlightGear, you may want to check out [[Nasal Modules]].&lt;br /&gt;
&lt;br /&gt;
If you are a developer and interested in extending Nasal, you may want to check out [[Howto:Extending Nasal]].&lt;br /&gt;
&lt;br /&gt;
Many short &amp;quot;howto&amp;quot;-style tutorials on Nasal programming can be found in the [[Category:Nasal|Nasal category]].&lt;br /&gt;
&lt;br /&gt;
== Some words on Nasal for fellow C++ programmers ==&lt;br /&gt;
&lt;br /&gt;
Compared to C++, there is really nothing &amp;quot;low quality&amp;quot; about Nasal per se: Nasal is just the &amp;quot;script glue&amp;quot; that connects different parts of the simulator: Many Nasal scripts leverage C++ code - and it is very easy to add new C++ code that can be called from Nasal. &lt;br /&gt;
&lt;br /&gt;
History has shown, that most code in FlightGear will eventually be made more configurable and more accessible, this usually happens in the same steps: 1) replacing static variables with variables stored in the property tree, 2) using listeners to get update notifications for important variables, 3) fully exposing a &amp;quot;control&amp;quot; interface by making it accessible it in the property tree, 4) providing scripting hooks.&lt;br /&gt;
&lt;br /&gt;
Even if you should know C or C++ already, Nasal probably remains the most accessible and the most powerful method for customizing the simulator, simply because it is extremely easy and fast to get started, you don't need an &amp;quot;integrated development environment&amp;quot;, you don't need to install compilers and you don't need to satisfy any 3rd party dependencies; bottom line being: if you can run FlightGear, you can also run Nasal and create new code.&lt;br /&gt;
&lt;br /&gt;
In addition, Nasal code is fairly abstract code, too. Once you start looking at some existing Nasal scripts, you will see that it is also fairly high level code, much more high level than C++ - so Nasal has a much higher density of code, too. Nasal's role in FlightGear really is like JavaScript's role in Firefox, where it is also used for many/most core-related logics (CSS/XUL). &lt;br /&gt;
&lt;br /&gt;
=== Performance ===&lt;br /&gt;
&lt;br /&gt;
Obviously, C++ code will usually be faster than the corresponding Nasal code. But, while performance is not a design goal, Nasal isn't especially slow either. For example, early benchmarks of the garbage collector showed it as faster than perl's reference counter, and its number crunching performance is on par with python. But in all cases, simplicity, transparency and a sane feature set are preferred over speed in Nasal. &lt;br /&gt;
&lt;br /&gt;
Nasal was specifically designed for use as an extension language in an larger project such as FlightGear. The problem with many otherwise excellent languages in this environment is that they are huge. Perl and python are great, but enormous. Even their &amp;quot;core&amp;quot; interpreters and library code are larger than most projects that require an embedded language. They cannot be readily shipped with their host application and need to be installed system-wide. This is a pain and a compatibility hassle. &lt;br /&gt;
&lt;br /&gt;
The real goal with Nasal is to have a language that supports most &amp;quot;normal&amp;quot; programming idioms (objects, functions, arrays, hashes) while avoiding the bloat that comes from &amp;quot;platform&amp;quot; scripting languages like perl, python, ruby and php.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Garbage collection ===&lt;br /&gt;
Nasal garbage collects runtime storage, so the programmer need not worry about manual allocation, or even circular references. The current implementation is a simple mark/sweep collector, which should be acceptable for most applications. Future enhancements will include a &amp;quot;return early&amp;quot; capability for latency-critical applications. The collector can be instructed to return after a certain maximum delay, and be restarted later. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As far as speed goes, the last time any benchmarking for Nasal was done, it was about as fast as Perl 5 or Python 2.2 at most things.  It's garbage collector was faster, its symbol lookup about the same or slightly faster, and its bytecode interpreter somewhat slower.&lt;br /&gt;
i&lt;br /&gt;
&lt;br /&gt;
=== Thread safety ===&lt;br /&gt;
Unlike almost all other script interpreters (and unlike the FlightGear/Nasal interface itself) , Nasal is thread safe and scalable when called from multiple CPU threads (as opposed to the userspace interpreter threads implemented by Ruby). &lt;br /&gt;
&lt;br /&gt;
No special treatment is required (as for perl, which clones a separate interpreter with separate data for each thread and uses locking around specifically-designated shared data) and the threads can be scheduled simultaneously. There is no global lock on the interpreter, as used by Python or Lua. The only limit on scalability is garbage collection, which must block all interpreter threads before running. &lt;br /&gt;
&lt;br /&gt;
When running threaded code, Nasal provides &amp;quot;minimal threadsafety&amp;quot;, meaning that the interpreter itself can be safely called from multiple CPU threads without risk of corrupting or deadlocking the interpreter internals. Multithreaded operations are therefore &amp;quot;safe&amp;quot;, although they are not guaranteed to be atomic. In particular, poorly synchronized insertions into containers can &amp;quot;drop&amp;quot; objects into oblivion (which is OK from an interpreter stability standpoint, since the GC will clean them up normally). Nasal itself provides no synchronization primitives to address this; thread architecture is a &amp;quot;top-level&amp;quot; design job, and Nasal is intended to be an extension language in a larger project. Choice of synchronization mechanisms is going to be highly application dependent. &lt;br /&gt;
&lt;br /&gt;
=== Exception handling ===&lt;br /&gt;
Like python, nasal supports exception handling as a first-class language feature, with built-in runtime-inspectable stack trace. Rather like perl, however, there is no special &amp;quot;try&amp;quot; syntax for exception handling, nor inheritance-based catching semantics. Instead, you use the call() builtin to invoke a function object and inspect the results to determine what error was thrown (either with the die() builtin or via an internal runtime error) and what the stack trace looked like. Elaborate exception handling isn't really appropriate for embedded scripting languages.&lt;br /&gt;
&lt;br /&gt;
=== High level programming ===&lt;br /&gt;
&lt;br /&gt;
Thus, programmers already familiar with C++ shouldn't just disregard Nasal as a &amp;quot;toy&amp;quot; that doesn't seem suitable for serious development: some of the more complex Nasal scripts can literally make one's head spin around and it would quite obviously take much more C++ or Java code to implement the same features, while sacrificing all the flexibility and power that a scripting language offers. &lt;br /&gt;
&lt;br /&gt;
Some features can certainly be more easily implemented in Nasal space, than in C++ space. Often, the Nasal solution is &amp;quot;on par&amp;quot; with similar solutions in C++.&lt;br /&gt;
&lt;br /&gt;
=== Accessibility ===&lt;br /&gt;
&lt;br /&gt;
For instance, Nasal code cannot only be easily run and contributed by all users, but it can also be easily reused and maintained by other users. This means, that given the number of active C++ developers, compared to the number of base package contributors, your Nasal code is more likely to be actively maintained by fellow users if it is written in Nasal. &lt;br /&gt;
&lt;br /&gt;
In other words, if there are some experimental features you'd like to explore, Nasal is an excellent way to ensure that other FlightGear '''users''' can easily test your new features. This could be witnessed during the development of the local weather system or the bombable addon,too.&lt;br /&gt;
&lt;br /&gt;
This is in stark contrast to features developed solely in C++ space, because these can usually only be tested by people able to build FlightGear from source, especially if your code isn't yet in the main repository, where it would eventually be available in the form of a binary snapshot.&lt;br /&gt;
&lt;br /&gt;
Obviously, none of this is to say that Nasal is the perfect solution for any problem, there are many things for which Nasal isn't necessarily a perfect choice, such as low level code for example (i.e. rendering).&lt;br /&gt;
&lt;br /&gt;
On the other hand, Nasal really is a powerful tool in FlightGear, and if you find that something should, but cannot, be done in Nasal space, it is extremely easy to add support for new features to the Nasal engine using extension functions or property listeners to trigger C/C++ code.&lt;br /&gt;
&lt;br /&gt;
== Creating new Scripts ==&lt;br /&gt;
&lt;br /&gt;
Nasal scripts need to be plain text files, saved with a *.nas extension.&lt;br /&gt;
&lt;br /&gt;
=== Aircraft specific Nasal code ===&lt;br /&gt;
&lt;br /&gt;
Generally, aircraft specific Nasal scripts reside in the corresponding aircraft's folder (or a corresponding /Nasal subfolder) where they are usually included by adding a corresponding &amp;lt;nasal&amp;gt; tag to the aircraft-set.xml file (see [[Writing_simple_scripts_in_%22nasal%22|Writing simple scripts in &amp;quot;nasal&amp;quot;]]). Also see the section on [[Nasal_scripting_language#Namespaces|namespaces]] which contains more specific examples.&lt;br /&gt;
&lt;br /&gt;
=== Instrument specific Nasal code ===&lt;br /&gt;
&lt;br /&gt;
While instrument specific scripts are saved within the instrument's folder (as previously mentioned, Nasal scripts can also be embedded in various other XML files), Nasal scripts driving shared instruments are generally stored in [[$FG ROOT]]/Aircraft/Generic/&lt;br /&gt;
&lt;br /&gt;
=== Nasal code as bindings in XML files ===&lt;br /&gt;
Nasal scripts can also be used as &amp;quot;binding&amp;quot; objects, and can therefore appear anywhere in a configuration file (keyboard, mouse and joystick bindings, etc...) that accepts a &amp;lt;binding&amp;gt; tag. The relevant command type is &amp;quot;nasal&amp;quot;, and you place your Nasal code inside of the &amp;lt;script&amp;gt; tag: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;binding&amp;gt;&lt;br /&gt;
  &amp;lt;command&amp;gt;nasal&amp;lt;/command&amp;gt;&lt;br /&gt;
  &amp;lt;script&amp;gt;&lt;br /&gt;
   print(&amp;quot;Binding Invoked!&amp;quot;);&lt;br /&gt;
  &amp;lt;/script&amp;gt;&lt;br /&gt;
 &amp;lt;/binding&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code above invokes the print() function. This is a simple extension function that simply prints out its arguments, in order, to the FlightGear console as a single-line log entry. It is useful for debugging, but little else. &lt;br /&gt;
&lt;br /&gt;
=== System-wide Nasal code ===&lt;br /&gt;
&lt;br /&gt;
Nasal scripts that are not specific to certain aircraft, instruments or other uses, generally reside in the system-wide [[$FG ROOT]]/Nasal directory.&lt;br /&gt;
&lt;br /&gt;
Nasal scripts that are placed inside [[$FG ROOT]]/Nasal (with a *.nas extension) are automatically loaded and run during FlightGear startup. &lt;br /&gt;
&lt;br /&gt;
=== Nasal sub modules ===&lt;br /&gt;
&lt;br /&gt;
As of 06/2011, FlightGear also supports so called Nasal &amp;quot;sub modules&amp;quot; which may reside in their own sub folder under $FG_ROOT/Nasal/ and which provide support for on-demand loading at runtime by toggling properties.&lt;br /&gt;
&lt;br /&gt;
Some advantages are:&lt;br /&gt;
&lt;br /&gt;
* Nasal files can be grouped neatly instead of all scripts being mixed up in a single fgdata/Nasal directory. Grouping makes a lot of sense for modules consisting of several scripts - local weather is the best example.&lt;br /&gt;
* Guaranteed loading sequence. Submodules are loaded _after_ the main fgdata/Nasal scripts, so they can rely on all fgdata/Nasal content to be already present. No more need for awkward listener callbacks, just to make sure that basic &amp;quot;props&amp;quot; or &amp;quot;gui&amp;quot; modules are available.&lt;br /&gt;
* Finally, users have the option to disable loading modules. Unfortunately, just loading scripts (code/data) into memory already causes certain _run-time_ performance effects - even if the Nasal code was never executed (so even when all listeners/timers were disabled).&lt;br /&gt;
&lt;br /&gt;
Please note that there is  a difference between the _individual_ Nasal files in fgdata/Nasal and files belonging to a common Nasal _module in general (no matter whether loaded at run-time or loaded at start-up using a &amp;quot;&amp;lt;nasal&amp;gt;&amp;quot; tag).&lt;br /&gt;
&lt;br /&gt;
The individual Nasal files in fgdata/Nasal have an own namespace _each_. The namespace get's the name of the Nasal file itself. So if you have a &amp;quot;gui.nas&amp;quot; in the directory, then you can reference a symbol &amp;quot;foo&amp;quot; using &amp;quot;gui.foo&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Nasal modules also have a single namespace. But all files belonging to the module share this _single_ namespace. The name of their namespace is made from its directory (for the run-time loadable modules), or from the specific tag given below the &amp;lt;nasal&amp;gt; XML element, which are often used for a/c specific modules (e.g. &amp;lt;nasal&amp;gt;&amp;lt;ufo&amp;gt;...&amp;lt;/ufo&amp;gt;&amp;lt;/nasal&amp;gt; creates the ufo Nasal namespace in ufo-set.xml).&lt;br /&gt;
&lt;br /&gt;
'''So each Nasal file in a new Nasal &amp;quot;module&amp;quot; folder now shares the same namespace.'''&lt;br /&gt;
&lt;br /&gt;
For more information on Nasal sub modules, please see [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg32657.html] and [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg33458.html].&lt;br /&gt;
&lt;br /&gt;
=== User specific Nasal scripts ===&lt;br /&gt;
&lt;br /&gt;
It's also possible to put Nasal files into $FG_HOME/Nasal/, that is: ~/.fgfs/Nasal/ on Unix, and %APPDATA%\flightgear.org\Nasal\ on MS Windows. This has the following advantages:&lt;br /&gt;
&lt;br /&gt;
* one doesn't have to mix local extensions with standard files&lt;br /&gt;
* one is less likely to lose such local additions when upgrading&lt;br /&gt;
* one doesn't need write permission to $FG_ROOT/Nasal/ or&lt;br /&gt;
* one doesn't have to become &amp;quot;root&amp;quot; to edit such files&lt;br /&gt;
&lt;br /&gt;
The files are guaranteed to be read after all the files in $FG_ROOT/Nasal/, so one can safely use elements of files like props.nas (props.Node), or globals.nas (setlistener() without leading underscore).&lt;br /&gt;
&lt;br /&gt;
The files are guaranteed to be read in alphabetic order. So, if there are two files where one depends on the other, just name them appropriately.&lt;br /&gt;
&lt;br /&gt;
The contents of each file are added to a namespace derived from the filename. So, all functions and variables of a file ~/.fgfs/nasal/local.nas will be added to nasal namespace &amp;quot;local&amp;quot;, and a function test() is globally accessible as local.test().&lt;br /&gt;
&lt;br /&gt;
It's possible to extend a standard module like &amp;quot;math&amp;quot; with definitions in ~/.fgfs/Nasal/math.nas, though this should, of course, not be exploited by code that is to be submitted to cvs.&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
&lt;br /&gt;
A simple hello world example in Nasal would be:&lt;br /&gt;
&lt;br /&gt;
 # hello.nas&lt;br /&gt;
 print('Hello World!');&lt;br /&gt;
&lt;br /&gt;
This will show the &amp;quot;Hello World&amp;quot; string during startup in the console window. The hash sign (#) just introduces comments (i.e. will be ignored by the interpreter).&lt;br /&gt;
&lt;br /&gt;
Note: Script-specific symbols such as global variables (or functions) will be put into a scope (namespace) based on the script's name, scripts embedded via aircraft-set.xml files can separately specify a corresponding module name (see [[Howto: Make an aircraft]] for details).&lt;br /&gt;
&lt;br /&gt;
Strings in Nasal can also use double quotes which support escaping:&lt;br /&gt;
 # hello.nas&lt;br /&gt;
 print(&amp;quot;Hello\nWorld!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Double quotes support typical escape sequences:&lt;br /&gt;
&lt;br /&gt;
* \n 	Newline&lt;br /&gt;
* \t	Horizontal Tab&lt;br /&gt;
* \v	Vertical Tab&lt;br /&gt;
* \b	Backspace&lt;br /&gt;
* \r	Carriage Return&lt;br /&gt;
* \f	Form feed&lt;br /&gt;
* \a	Audible Alert (bell)&lt;br /&gt;
* \\	Backslash&lt;br /&gt;
* \?	Question mark&lt;br /&gt;
* \'	Single quote&lt;br /&gt;
* \&amp;quot;	Double quote&lt;br /&gt;
&lt;br /&gt;
For example, to print a new line, use:&lt;br /&gt;
&lt;br /&gt;
 print (&amp;quot;\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
To print a quoted string, use:&lt;br /&gt;
&lt;br /&gt;
 print (&amp;quot;\&amp;quot;quoted string\&amp;quot;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
and so on.&lt;br /&gt;
&lt;br /&gt;
Single quotes treat everything as literal except for embedded single quotes (including embedded whitespace like newlines).&lt;br /&gt;
&lt;br /&gt;
Nasal strings are always arrays of bytes (never characters: see the utf8 library if you want character-based equivalents of substr() et. al.). They can be indexed just like in C (although note that there is no nul termination -- get the length with size()):&lt;br /&gt;
&lt;br /&gt;
== Editing code files ==&lt;br /&gt;
&lt;br /&gt;
Note that there is currently no way to tell FlightGear to reload Nasal scripts from the global Nasal directory at runtime, so in order to see changes take effect, you will have to exit and restart FlightGear for the time being. Note that there are some workarounds available, see: [[Nasal_scripting_language#Loading.2Freloading_Nasal_code_without_re-starting_Flightgear|reloading Nasal code without re-starting FlightGear]].&lt;br /&gt;
&lt;br /&gt;
Also, note that as of 05/2009, Nasal in FlightGear does not yet support any form of dependency resolution. In other words, there's no &amp;quot;import&amp;quot;, &amp;quot;require&amp;quot; or &amp;quot;include&amp;quot; directive - this is also why most code in FlightGear is wrapped inside a _setlistener() call instead, which in turn waits for a FlightGear signal before executing the code (see below for details).&lt;br /&gt;
&lt;br /&gt;
== Variables ==&lt;br /&gt;
Nasal scripts should make use of the var keyword when declaring variables. The &amp;quot;var&amp;quot; keyword makes a variable guaranteed to be local. Nasal, natively provides support for scalars (numbers, strings), lists (arrays, vectors) and hashes (objects or dictionaries), more complex data structures (such as trees) can be built using vectors or hashes.&lt;br /&gt;
&lt;br /&gt;
 var w=100;     # w is a local numerical variable&lt;br /&gt;
 var x=&amp;quot;hello&amp;quot;; # x is a local string variable&lt;br /&gt;
 var y=[];      # y is a local vector (array)&lt;br /&gt;
 var z={};      # z is a local hash (dictionary or table) - also used for OOP&lt;br /&gt;
&lt;br /&gt;
Nasal supports a &amp;quot;nil&amp;quot; value for use as a null pointer equivalent:&lt;br /&gt;
&lt;br /&gt;
 var foo=nil; &lt;br /&gt;
&lt;br /&gt;
Also, note that Nasal symbols are case-sensitive, these are all different variables:&lt;br /&gt;
&lt;br /&gt;
 var show = func(what) {print(what,&amp;quot;\n&amp;quot;);}&lt;br /&gt;
 var abc=1; # these are all different symbols&lt;br /&gt;
 var ABC=2; # different from abc &lt;br /&gt;
 var aBc=3; # different from abc and ABC&lt;br /&gt;
 &lt;br /&gt;
 show(abc);&lt;br /&gt;
 show(ABC);&lt;br /&gt;
 show(aBc);&lt;br /&gt;
&lt;br /&gt;
Please note that functions assigned to variables are no exception. If you write code without using &amp;quot;var&amp;quot; on variables, then you risk (often hard to debug) breakage at a later time because you may be overwriting symbols in another namespace. &lt;br /&gt;
&lt;br /&gt;
So functions bound to variables should use the &amp;quot;var&amp;quot; keyword as well:&lt;br /&gt;
&lt;br /&gt;
 var hello = func { &lt;br /&gt;
   print(&amp;quot;hello\n&amp;quot;); &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
But there's another reason why &amp;quot;var&amp;quot; should be used consequently, even if a variable is safe enough from later side effects, because it has a relatively specific or unique name: The &amp;quot;var&amp;quot; keyword makes&lt;br /&gt;
reading code for others (and for the author after some time) easier, as it makes clear: &amp;quot;this variable starts its life *HERE*&amp;quot;. No need to search around to see whether assigning a value to it means something to other code outside or not. Also, with an editor offering proper syntax highlighting reading such code is actually easier, despite the &amp;quot;noise&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The problem with nasal code that does not make use of the var keyword is, that it can break other code, and with it the whole system, but no Nasal error message will point you there, as it's syntactically and semantically correct code. Just doing things that it wasn't supposed to do.&lt;br /&gt;
For a more in-depth discussion, please see [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg13557.html].&lt;br /&gt;
&lt;br /&gt;
Also, Nasal scripts that are loaded from $FG_ROOT/Nasal are automatically placed inside a namespace that is based on the script's name.&lt;br /&gt;
&lt;br /&gt;
For example, referring to our earlier &amp;quot;Hello World&amp;quot; example, global variables defined in the hello.nas script would be accessible by using &amp;quot;hello&amp;quot; as prefix from other modules:&lt;br /&gt;
&lt;br /&gt;
 # hello.nas&lt;br /&gt;
 var greeting=&amp;quot;Hello World&amp;quot;; # define a greeting symbol inside the hello namespace&lt;br /&gt;
&lt;br /&gt;
If you were now to read out the value from the greeting variable from another Nasal module, you would have to use the hello prefix:&lt;br /&gt;
&lt;br /&gt;
 # greetme.nas&lt;br /&gt;
 print(hello.greeting); # the hello prefix is referring to the hello namespace (or module).&lt;br /&gt;
&lt;br /&gt;
==Namespaces==&lt;br /&gt;
The Nasal Console built into FlightGear is quite handy when it comes to debugging code. However, here the namespaces need to be considered. In addition, Nasal sub modules (see above) have some special rules, too - basically, all Nasal files part of a &amp;quot;sub module&amp;quot; share a single name space based on the folder's name rather than the name of the individual Nasal files.&lt;br /&gt;
&lt;br /&gt;
For cases of Nasal code specific for an aircraft (like instruments, for example), the corresponding scripts could be loaded through the aircraft's &amp;lt;tt&amp;gt;-set.xml&amp;lt;/tt&amp;gt; file by putting it into the &amp;lt;tt&amp;gt;&amp;lt;nasal&amp;gt;...&amp;lt;/nasal&amp;gt;&amp;lt;tt&amp;gt; section&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;nasal&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;moduleA&amp;gt;&lt;br /&gt;
      &amp;lt;file&amp;gt;path/to/file1.nas&amp;lt;/file&amp;gt;&lt;br /&gt;
      &amp;lt;file&amp;gt;path/to/file2.nas&amp;lt;/file&amp;gt;		&lt;br /&gt;
    &amp;lt;/moduleA&amp;gt;&lt;br /&gt;
    &amp;lt;moduleB&amp;gt;&lt;br /&gt;
      &amp;lt;file&amp;gt;path/to/file3.nas&amp;lt;/file&amp;gt;	&lt;br /&gt;
    &amp;lt;/moduleB&amp;gt;&lt;br /&gt;
  &amp;lt;/nasal&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, variables in files &amp;lt;tt&amp;gt;path/to/file1.nas&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;path/to/file2.nas&amp;lt;/tt&amp;gt; can be used in the Nasal console as&lt;br /&gt;
&lt;br /&gt;
  moduleA.varName;&lt;br /&gt;
&lt;br /&gt;
Variables in &amp;lt;tt&amp;gt;path/to/file3.nas&amp;lt;/tt&amp;gt; can be accessed as&lt;br /&gt;
&lt;br /&gt;
  moduleB.varName;&lt;br /&gt;
&lt;br /&gt;
Please note that Nasal sub modules (i.e. files loaded and run from their own Nasal sub directory), are subject to some special rules, as all Nasal source files are automatically loaded into the same namespace, which is by default based on the sub module's folder name.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''More information can be found by clicking [http://wiki.flightgear.org/Namespaces_and_Methods here].'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Variables - Advanced Uses ==&lt;br /&gt;
&lt;br /&gt;
Nasal, also supports Multi-assignment expressions. You can assign more than one variable (or lvalue) at a time by putting them in a parenthesized list:&lt;br /&gt;
&lt;br /&gt;
   (var a, var b) = (1, 2);&lt;br /&gt;
   var (a, b) = (1, 2);               # Shorthand for (var a, var b)&lt;br /&gt;
   (var a, v[0], obj.field) = (1,2,3) # Any assignable lvalue works&lt;br /&gt;
   var color = [1, 1, 0.5];&lt;br /&gt;
   var (r, g, b) = color;  # works with runtime vectors too&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Vectors (lists or arrays) can be created from others using an ordered list of indexes and ranges. &lt;br /&gt;
This is usually called &amp;quot;vector slicing&amp;quot;.&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
   var v1 = [&amp;quot;a&amp;quot;,&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;,&amp;quot;d&amp;quot;,&amp;quot;e&amp;quot;]&lt;br /&gt;
   # &lt;br /&gt;
   var v2 = v1[3,2];   # == [&amp;quot;d&amp;quot;,&amp;quot;c&amp;quot;];&lt;br /&gt;
   var v3 = v1[1:3];   # i.e. range from 1 to 3: [&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;,&amp;quot;d&amp;quot;];&lt;br /&gt;
   var v4 = v1[1:];    # no value means &amp;quot;to the end&amp;quot;: [&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;,&amp;quot;d&amp;quot;,&amp;quot;e&amp;quot;]&lt;br /&gt;
   var i = 2;&lt;br /&gt;
   var v5 = v1[i];     # runtime expressions are fine: [&amp;quot;c&amp;quot;]&lt;br /&gt;
   var v6 = v1[-2,-1]; # negative indexes are relative to end: [&amp;quot;d&amp;quot;,&amp;quot;e&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
The range values can be computed at runtime (e.g. i=1; v5=v1[i:]). Negative indices work the same way they do with the vector functions (-1 is the last element, -2 is 2nd to last, etc...).&lt;br /&gt;
&lt;br /&gt;
== Storage: property tree vs. Nasal ==&lt;br /&gt;
With FlightGear's built-in property tree and Nasal's support for it, there are two obvious, and two somewhat competing, ways for storing scalar data: native Nasal variables and FlightGear properties, both of which can be easily accessed and managed from Nasal.&lt;br /&gt;
&lt;br /&gt;
The advantage to native Nasal-space data is that it's fast and simple.  If the only thing that will care about the value is your script, they are good choices.&lt;br /&gt;
&lt;br /&gt;
The property tree is an inter-subsystem communication thing.  This is what you want if you want to share data with the C++ world (for example, YASim &amp;lt;control-output&amp;gt; tags write to properties -- they don't understand Nasal), or read in via configuration files.&lt;br /&gt;
&lt;br /&gt;
Also, native Nasal data structures are usually far faster than their equivalent in property tree space.  This is because there are several layers of indirection in retrieving a property tree value. &lt;br /&gt;
&lt;br /&gt;
In general, this means that you shouldn't make overly excessive use of the property tree for storing state that isn't otherwise relevant to FlightGear or any of its subsystems. Doing that would in fact have adverse effects on the performance of your code. In general, you should favor Nasal variables and data structures and should only make use of properties to interface with the rest of FlightGear, or to easily provide debugging information at run time.&lt;br /&gt;
&lt;br /&gt;
As of FG 2.4.0, retrieving a value from the property tree via getprop is about 50% slower than accessing a native Nasal variable, and accessing the value via node.getValue() is 10-20% slower yet. This is an insignificant amount of time if you are retrieving and storing a few individual values from the property tree, but adds up fast if you are storing or retrieving hashes or large amounts of data.  (You can easily benchmark times on your own code using systime() or debug.benchmark.)&lt;br /&gt;
&lt;br /&gt;
In addition, it is worth noting that the Nasal/FlightGear APIs cannot currently be considered to be thread safe, this mean that -at least for now- the explicit use of pure Nasal space variables is the only way to exploit possible parallelism in your code by making use of threads.&lt;br /&gt;
&lt;br /&gt;
== Functions ==&lt;br /&gt;
&lt;br /&gt;
=== What is a function ? ===&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;function&amp;quot; is a piece of code that can be easily used repeatedly (without repeating the same code over and over again), this is achieved by associating a symbolic name with the piece of code, such as &amp;quot;print&amp;quot;, &amp;quot;show&amp;quot; or &amp;quot;get&amp;quot; for example. Whenever this symbolic name is then used in the program, the program will &amp;quot;jump&amp;quot; to the definition of the function and start running it, once the called function has completed it will automatically return to the instruction following the call.&lt;br /&gt;
&lt;br /&gt;
By using so called &amp;quot;function arguments&amp;quot; (see below) it is possible to parametrize a function (using variables) so that it may use data that is specific to each invocation.&lt;br /&gt;
&lt;br /&gt;
As previously shown, Nasal functions are implemented using the func keyword, The following snippet of code defines a new function named &amp;quot;log_message&amp;quot; with an empty function body (the curly braces).&lt;br /&gt;
&lt;br /&gt;
 var log_message = func {}&lt;br /&gt;
&lt;br /&gt;
=== Function bodies ===&lt;br /&gt;
&lt;br /&gt;
To add a function body, you need to add code in between these curly braces.&lt;br /&gt;
&lt;br /&gt;
=== Anonymous function arguments ===&lt;br /&gt;
&lt;br /&gt;
In Nasal, arguments are by default passed in the &amp;quot;arg&amp;quot; array, not unlike perl. To understand how this works, you should probably first read up on Nasal vectors.&lt;br /&gt;
&lt;br /&gt;
 var log_message = func {&lt;br /&gt;
    print(arg[0]);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Note that this is equivalent to:&lt;br /&gt;
&lt;br /&gt;
 var log_message = func() {&lt;br /&gt;
    print(arg[0]);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In other words, the argument list &amp;quot;()&amp;quot; can be omitted if it is empty.&lt;br /&gt;
However, if you are new to Nasal or programming in general, it is probably a good idea to ALWAYS use parentheses, i.e. also for functions with empty argument lists - that makes it easy to get used to the syntax.&lt;br /&gt;
&lt;br /&gt;
Note that this is just an assignment of an (anonymous) function argument to the local &amp;quot;log_message&amp;quot; variable. There is no function declaration syntax in Nasal.&lt;br /&gt;
&lt;br /&gt;
Also, Nasal being a functional programming language, all passed arguments will be local to the corresponding scope. If you want to modify state in a function, you'll preferably return new state to the caller.&lt;br /&gt;
&lt;br /&gt;
===Named function arguments===&lt;br /&gt;
You can also pass named arguments to a function, thus saving the typing and performance costs of extracting them from the arg array:&lt;br /&gt;
&lt;br /&gt;
 var log_message = func(msg) {&lt;br /&gt;
    print(msg);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The list of function arguments is called a function's &amp;quot;signature&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Default values for function arguments ===&lt;br /&gt;
&lt;br /&gt;
Function arguments can have default values, as in C++. Note that the default value must be a scalar (number, string, function, nil) and not a mutable composite object (list, hash).&lt;br /&gt;
&lt;br /&gt;
 var log_message = func(msg=&amp;quot;error&amp;quot;) {&lt;br /&gt;
    print(msg);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If some arguments have default values and some do not, those with default values must come first in the argument list:&lt;br /&gt;
&lt;br /&gt;
 #Incorrect:&lt;br /&gt;
 var log_message = func(msg=&amp;quot;error&amp;quot;, line, object=&amp;quot;ground&amp;quot;) { #some code }&lt;br /&gt;
&lt;br /&gt;
 #Correct:&lt;br /&gt;
 var log_message = func(msg=&amp;quot;error&amp;quot;, object=&amp;quot;ground&amp;quot;, line) { #some code }&lt;br /&gt;
&lt;br /&gt;
Any extra arguments after the named list are placed in the &amp;quot;arg&amp;quot; vector as above. You can rename this to something other than &amp;quot;arg&amp;quot; by specifying a final argument name with an ellipsis:&lt;br /&gt;
&lt;br /&gt;
 listify = func(elements...) { return elements; }&lt;br /&gt;
 listify(1, 2, 3, 4); # returns a list: [1, 2, 3, 4]&lt;br /&gt;
&lt;br /&gt;
=== Returning from functions ===&lt;br /&gt;
&lt;br /&gt;
In Nasal, functions return implicitly the values of the last expression (i.e. &amp;quot;nil&amp;quot; in empty function bodies), you can also add an explicit &amp;quot;return&amp;quot; statement, for example to leave a function early. In addition, it is possible to return values, too.&lt;br /&gt;
&lt;br /&gt;
So, semantically, the previous snippet of code is equivalent to these:&lt;br /&gt;
&lt;br /&gt;
 var log_message = func {return;}&lt;br /&gt;
&lt;br /&gt;
 var log_message = func {nil;}&lt;br /&gt;
&lt;br /&gt;
 var log_message = func {}; &lt;br /&gt;
&lt;br /&gt;
 var log_message = func return;&lt;br /&gt;
&lt;br /&gt;
 var log_message = func nil;&lt;br /&gt;
&lt;br /&gt;
===Named arguments in function calls===&lt;br /&gt;
Nasal supports named function arguments in function calls, too.&lt;br /&gt;
&lt;br /&gt;
As an alternative to the comma-separated list of ''positional'' function arguments, you can specify a hash literal in place of ordered function arguments, and it will become the local variable namespace for the called function, with variables named according to the hash indexes and with values according to the hash values.  This makes functions with many arguments more readable. &lt;br /&gt;
&lt;br /&gt;
And it also makes it possible to call function's without having to take care of the right order of passing arguments.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
 #if we have functions defined:&lt;br /&gt;
 var log_message = func (msg=&amp;quot;&amp;quot;) { #some code to log variable msg }&lt;br /&gt;
 var lookat =  func (heading=0, pitch=0, roll=0, x=nil, y=nil, z=nil, time=hil, fov=20) { #some code using those variables }&lt;br /&gt;
&lt;br /&gt;
 #we can use them them the usual way with comma separated list of arguments:&lt;br /&gt;
 log_message(&amp;quot;Hello World!&amp;quot;);&lt;br /&gt;
 lookat (180, 20, 0, XO, YO, ZO, now, 55);&lt;br /&gt;
&lt;br /&gt;
 #or we can use the hash literal arguments instead:&lt;br /&gt;
 log_message(msg:&amp;quot;Hello World!&amp;quot;);&lt;br /&gt;
 lookat(heading:180, pitch:20, roll:0, x:X0, y:Y0, z:Z0,time:now, fov:55);&lt;br /&gt;
&lt;br /&gt;
Both methods for calling the functions above are equivalent, but note the the second method is more readable, less prone to error, and self-documenting in the code for the function call.&lt;br /&gt;
&lt;br /&gt;
As another example, consider:&lt;br /&gt;
&lt;br /&gt;
 var setPosition = func (latitude_deg, longitude_deg, altitude_ft) {&lt;br /&gt;
  # do something here &lt;br /&gt;
 }&lt;br /&gt;
 # the actual function call:&lt;br /&gt;
 setPosition( latitude_deg:34.00, longitude_deg:7.00, alt_ft:10000);&lt;br /&gt;
&lt;br /&gt;
In other words, such function calls become much more self-explanatory because everybody can see immediately what a value is doing.&lt;br /&gt;
This is a good practice, as you may eventually have to take a longer break, away from your code - and then even you yourself will come to appreciate such small things that make code more intuitive to work with.&lt;br /&gt;
&lt;br /&gt;
Declared arguments are checked and defaulted as would be expected: it's an error if you fail to pass a value for an undefaulted argument, missing default arguments get assigned as usual, and any rest parameter (e.g. &amp;quot;func(a,b=2,rest...){}&amp;quot;) will be assigned with an empty vector.&lt;br /&gt;
&lt;br /&gt;
===Nested functions, implicit return ===&lt;br /&gt;
Also, Nasal functions can be easily nested, for example:&lt;br /&gt;
&lt;br /&gt;
  var calculate = func(param1,param2,operator) {&lt;br /&gt;
   var add = func(p1,p2) {p1+p2;}&lt;br /&gt;
   var sub = func(p1,p2) {p1-p2;}&lt;br /&gt;
   var mul = func(p1,p2) {p1*p2;}&lt;br /&gt;
   var div = func(p1,p2) {p1/p2;}&lt;br /&gt;
   if (operator==&amp;quot;+&amp;quot;) return add(param1,param2);&lt;br /&gt;
   if (operator==&amp;quot;-&amp;quot;) return sub(param1,param2);&lt;br /&gt;
   if (operator==&amp;quot;*&amp;quot;) return mul(param1,param2);&lt;br /&gt;
   if (operator==&amp;quot;/&amp;quot;) return div(param1,param2);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Note that the add,sub,mul and div functions in this example do not make use of an explicit return statement, instead the result of each expression is implicitly returned to the caller.&lt;br /&gt;
&lt;br /&gt;
Nasal functions that just consist of such simple expressions can also be further simplified to read:&lt;br /&gt;
&lt;br /&gt;
  var add = func(val1,val2) val1+val2;&lt;br /&gt;
&lt;br /&gt;
=== Function overloading ===&lt;br /&gt;
&lt;br /&gt;
Note that Nasal functions can generally not be [[http://en.wikipedia.org/wiki/Function_overloading overloaded]], and that operator overloading in particular is also not supported.&lt;br /&gt;
&lt;br /&gt;
However, the effects of '''function overloading''' can obviously be implemented individually by each function, simply by processing the number and type of passed arguments at the start of the function body. The FlightGear code base contains a number of examples for this, i.e. it is for example possible to pass properties in the form of plain strings to a callback or in the form of a Nasal wrapper like props.Node.&lt;br /&gt;
&lt;br /&gt;
So this can be accomplished by first checking the argument count and then the types of arguments passed to the function.&lt;br /&gt;
&lt;br /&gt;
To provide an example, here's a simple function to multiply two numbers, no matter if they are provided as scalars, as a vector or as x/y members of a hash:&lt;br /&gt;
&lt;br /&gt;
 var multiply2 = func (params) {&lt;br /&gt;
  if (typeof(params)==&amp;quot;scalar&amp;quot;) return params*arg[0];&lt;br /&gt;
  if (typeof(params)==&amp;quot;vector&amp;quot;) return params[0]*params[1];&lt;br /&gt;
  if (typeof(params)==&amp;quot;hash&amp;quot;)   return params.x*params.y;&lt;br /&gt;
  die(&amp;quot;cannot do what you want me to do&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
So, now you have a very simple form of an &amp;quot;overloaded&amp;quot; function that supports different argument types and numbers:&lt;br /&gt;
&lt;br /&gt;
 multiply2(  2,6); # multiply two scalars&lt;br /&gt;
 multiply2( [5,7] ); # multiply two scalars stored in a vector&lt;br /&gt;
 multiply2( {x:8, y:9} ); # multiply two scalars stored in a hash&lt;br /&gt;
&lt;br /&gt;
You could obviously extend this easily to support an arbitrary number of arguments by just using a for loop here.&lt;br /&gt;
&lt;br /&gt;
As you can see, the basic idea is pretty simple and also scalable, you could easily extend this to and also return different types of values, such as vectors or hashes. This could for example be used to create wrappers in Nasal space for doing 3D maths, with vectors and matrices, so that a matrix multiplication could return a new matrix, too.&lt;br /&gt;
&lt;br /&gt;
===Functional programming, higher order functions, generators;===&lt;br /&gt;
As previously mentioned, arguments to a Nasal function can also be functions themselves (Nasal being a functional programming language), this means that Nasal functions are higher order functions so that you can easily pass and return functions to and from Nasal functions. This can for example be used to dynamically create new functions (such functions are commonly called 'generators'):&lt;br /&gt;
&lt;br /&gt;
  # a function that returns a new custom function&lt;br /&gt;
  var i18n_hello = func(hello) {&lt;br /&gt;
   return func(name) { # returns an anonymous/unnamed function&lt;br /&gt;
     print(hello,name);&lt;br /&gt;
   }&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
  # create three new functions&lt;br /&gt;
  var english_hello = i18n_hello(&amp;quot;Good Day &amp;quot;);&lt;br /&gt;
  var spanish_hello = i18n_hello(&amp;quot;Buenos Dias &amp;quot;);&lt;br /&gt;
  var italian_hello = i18n_hello(&amp;quot;Buon giorno &amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
  # actually call these functions&lt;br /&gt;
  english_hello(&amp;quot;FlightGear&amp;quot;);&lt;br /&gt;
  spanish_hello(&amp;quot;FlightGear&amp;quot;);&lt;br /&gt;
  italian_hello(&amp;quot;FlightGear&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
=== Using helper functions ===&lt;br /&gt;
&lt;br /&gt;
It is possible to simplify complex function calls by introducing small helper functions, for example consider:&lt;br /&gt;
&lt;br /&gt;
 var l = thermalLift.new(ev.lat, ev.lon, ev.radius, ev.height, ev.cn, ev.sh, ev.max_lift, ev.f_lift_radius);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, you could just as well create a small helper function named&amp;quot;thermalLift.new_from_ev(ev)&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
  thermalLift.new_from_ev = func (ev) {&lt;br /&gt;
   thermalLift.new(ev.lat, ev.lon, ev.radius, ev.height, ev.cn, ev.sh, ev.max_lift, ev.f_lift_radius);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 var l=thermalLift.new_from_ev(ev);&lt;br /&gt;
&lt;br /&gt;
Note that the expression to invoke your code would then also become less complicated and much more comprehensible.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you have expressions of nested method calls, such as:&lt;br /&gt;
&lt;br /&gt;
    t.getNode(&amp;quot;latitude-deg&amp;quot;).setValue(f.getNode(&amp;quot;latitude-deg&amp;quot;).getValue());&lt;br /&gt;
    t.getNode(&amp;quot;longitude-deg&amp;quot;).setValue(f.getNode(&amp;quot;longitude-deg&amp;quot;).getValue());&lt;br /&gt;
&lt;br /&gt;
You could just as easily introduce a small helper function to wrap the code, that would be less typing for you, less code to read (and understand) for others and generally it would help localize functionality (and possible errors):&lt;br /&gt;
&lt;br /&gt;
    var copyNode = func(t,f,path) t.getNode(path).setValue(f.getNode(path).getValue());&lt;br /&gt;
&lt;br /&gt;
So you would simply take the complex expression and generalize it by adding variables that you pass in from a function object, then you could simply call your new function like this:&lt;br /&gt;
&lt;br /&gt;
    copyNode(t,f,&amp;quot;latitude-deg&amp;quot;);&lt;br /&gt;
    copyNode(t,f,&amp;quot;longitude-deg&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
    foreach(var p; [&amp;quot;latitude-deg&amp;quot;, &amp;quot;longitude-deg&amp;quot;,&amp;quot;generated-flag&amp;quot;])&lt;br /&gt;
      copyNode(t,f,p);&lt;br /&gt;
&lt;br /&gt;
or as a complete function accepting a vector of properties:&lt;br /&gt;
&lt;br /&gt;
    var copyNode = func(target,source,properties) { &lt;br /&gt;
     if (typeof(properties)!=&amp;quot;vector&amp;quot;) properties=[properties];&lt;br /&gt;
     if (typeof(target)!=&amp;quot;hash&amp;quot;) target=props.globals.getNode(target);&lt;br /&gt;
     if (typeof(source)!=&amp;quot;hash&amp;quot;) target=props.globals.getNode(source)&lt;br /&gt;
     foreach(var path; properties)&lt;br /&gt;
      target.getNode(path).setValue( source.getNode(path).getValue() );&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    copyNode(&amp;quot;/temp/test&amp;quot;, &amp;quot;/position&amp;quot;, [&amp;quot;latitude-deg&amp;quot;, &amp;quot;longitude-deg&amp;quot;, &amp;quot;altitude-ft&amp;quot;]);&lt;br /&gt;
&lt;br /&gt;
Whenever you have very similar lines of code that seem fairly repetitive, it is a good idea to consider introducing small helper functions. You can use plenty of small helper functions and then just &amp;quot;chain&amp;quot; them together, rather than using complex nested expressions that make your head spin.&lt;br /&gt;
&lt;br /&gt;
== Conditionals ==&lt;br /&gt;
&lt;br /&gt;
Nasal has no &amp;quot;statements&amp;quot;, which means that any expression can appear in any context. This means that you can use an if/else clause to do what the ?: does in C. &lt;br /&gt;
The last semicolon in a code block is optional, to make this prettier&lt;br /&gt;
&lt;br /&gt;
 abs = func(n) { if(n&amp;lt;0) { -n } else { n } }&lt;br /&gt;
&lt;br /&gt;
But for those who don't like typing, the ternary operator works like you expect:&lt;br /&gt;
&lt;br /&gt;
 abs = func(n) { n &amp;lt; 0 ? -n : n }&lt;br /&gt;
&lt;br /&gt;
In addition, Nasal supports braceless blocks, like they're known from C/C++ and other languages:&lt;br /&gt;
&lt;br /&gt;
 var foo=1;&lt;br /&gt;
 if (foo)&lt;br /&gt;
   print(&amp;quot;1\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
   print(&amp;quot;0\n&amp;quot;);&lt;br /&gt;
 print(&amp;quot;this is printed regardless\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Instead of a switch statement one can use&lt;br /&gt;
&lt;br /&gt;
  if (1==2) {&lt;br /&gt;
    print(&amp;quot;wrong&amp;quot;);&lt;br /&gt;
  } else if (1==3) { # NOTE the space between else and if&lt;br /&gt;
    print(&amp;quot;wronger&amp;quot;);&lt;br /&gt;
  } else {&lt;br /&gt;
    print(&amp;quot;don't know&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
which produces the expected output of &amp;lt;code&amp;gt;don't know&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;nil&amp;lt;/tt&amp;gt; logic is actually quite logical, let's just restate the obvious:&lt;br /&gt;
&lt;br /&gt;
  if (nil) {&lt;br /&gt;
    print(&amp;quot;This should never be printed&amp;quot;);&lt;br /&gt;
  } else {&lt;br /&gt;
    print(&amp;quot;This will be printed, because nil is always false&amp;quot;);		&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nasal's binary boolean operators are &amp;quot;and&amp;quot; and &amp;quot;or&amp;quot;, unlike C. unary not is still &amp;quot;!&amp;quot; however. &lt;br /&gt;
They short-circuit like you expect&lt;br /&gt;
&lt;br /&gt;
 var toggle = 0;&lt;br /&gt;
 var a = nil;&lt;br /&gt;
 if(a and a.field == 42) {&lt;br /&gt;
    toggle = !toggle; # doesn't crash when a is nil&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
You can easily reduce the complexity of huge conditional (IF) statements, such as this one:&lt;br /&gt;
&lt;br /&gt;
    if (a==1) function_a();&lt;br /&gt;
    else&lt;br /&gt;
    if (a==2) function_b();&lt;br /&gt;
    else&lt;br /&gt;
    if (a==3) function_c();&lt;br /&gt;
    else&lt;br /&gt;
    if (a==4) function_d();&lt;br /&gt;
    else&lt;br /&gt;
    if (a==5) function_e();&lt;br /&gt;
&lt;br /&gt;
.. just by using the variable as a key (index) into a hash, so that you can directly call the corresponding function:&lt;br /&gt;
&lt;br /&gt;
    var mapping = {1:function_a, 2:function_b, 3:function_c, 4:function_d,5:function_e};&lt;br /&gt;
    mapping[a] ();&lt;br /&gt;
&lt;br /&gt;
This initializes first a hash map of values and maps a function &amp;quot;pointer&amp;quot; to each value, so that accessing mapping[x] will return the function pointer for the key &amp;quot;x&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Next, you can actually call the function by appending a list of function arguments (empty parentheses for no args) to the hash lookup.&lt;br /&gt;
&lt;br /&gt;
Using this technique, you can reduce the complexity of huge conditional blocks. For example, consider:&lt;br /&gt;
&lt;br /&gt;
    # weather_tile_management.nas&lt;br /&gt;
    460         if (code == &amp;quot;altocumulus_sky&amp;quot;){weather_tiles.set_altocumulus_tile();}&lt;br /&gt;
    461         else if (code == &amp;quot;broken_layers&amp;quot;) {weather_tiles.set_broken_layers_tile();}&lt;br /&gt;
    462         else if (code == &amp;quot;stratus&amp;quot;) {weather_tiles.set_overcast_stratus_tile();}&lt;br /&gt;
    463         else if (code == &amp;quot;cumulus_sky&amp;quot;) {weather_tiles.set_fair_weather_tile();}&lt;br /&gt;
    464         else if (code == &amp;quot;gliders_sky&amp;quot;) {weather_tiles.set_gliders_sky_tile();}&lt;br /&gt;
    465         else if (code == &amp;quot;blue_thermals&amp;quot;) {weather_tiles.set_blue_thermals_tile();}&lt;br /&gt;
    466         else if (code == &amp;quot;summer_rain&amp;quot;) {weather_tiles.set_summer_rain_tile();}&lt;br /&gt;
    467         else if (code == &amp;quot;high_pressure_core&amp;quot;) {weather_tiles.set_high_pressure_core_tile();}&lt;br /&gt;
    468         else if (code == &amp;quot;high_pressure&amp;quot;) {weather_tiles.set_high_pressure_tile();}&lt;br /&gt;
    469         else if (code == &amp;quot;high_pressure_border&amp;quot;) {weather_tiles.set_high_pressure_border_tile();}&lt;br /&gt;
    470         else if (code == &amp;quot;low_pressure_border&amp;quot;) {weather_tiles.set_low_pressure_border_tile();}&lt;br /&gt;
    471         else if (code == &amp;quot;low_pressure&amp;quot;) {weather_tiles.set_low_pressure_tile();}&lt;br /&gt;
    472         else if (code == &amp;quot;low_pressure_core&amp;quot;) {weather_tiles.set_low_pressure_core_tile();}&lt;br /&gt;
    473         else if (code == &amp;quot;cold_sector&amp;quot;) {weather_tiles.set_cold_sector_tile();}&lt;br /&gt;
    474         else if (code == &amp;quot;warm_sector&amp;quot;) {weather_tiles.set_warm_sector_tile();}&lt;br /&gt;
    475         else if (code == &amp;quot;tropical_weather&amp;quot;) {weather_tiles.set_tropical_weather_tile();}&lt;br /&gt;
    476         else if (code == &amp;quot;test&amp;quot;) {weather_tiles.set_4_8_stratus_tile();}&lt;br /&gt;
    477         else ...&lt;br /&gt;
&lt;br /&gt;
While this is not a very complex or huge block of code, it is an excellent example for very good naming conventions used already, because the consistency of naming variables and functions can pay off easily here, with just some very small changes, you can already reduce the whole thing to a hash lookup like this:&lt;br /&gt;
&lt;br /&gt;
  weather_tiles[&amp;quot;set_&amp;quot;~code~&amp;quot;_tile&amp;quot;]();  # naming convention&lt;br /&gt;
&lt;br /&gt;
This would dynamically concatenate a key consisting of &amp;quot;set_&amp;quot; + code + &amp;quot;_title&amp;quot; into the hash named weather_tiles, and then call the function that is returned from the hash lookup.&lt;br /&gt;
&lt;br /&gt;
So for this to work you only need to enforce consistency when naming your functions (i.e. this would of course CURRENTLY fail when the variable code contains &amp;quot;test&amp;quot; because there is no such hash member (it's &amp;quot;4_8_stratus&amp;quot; instead).&lt;br /&gt;
&lt;br /&gt;
The same applies to cumulus sky (fair weather), stratus/overcast stratus.&lt;br /&gt;
&lt;br /&gt;
But these are very simple changes to do (just renaming these functions to match the existing conventions). When you do that, you can easily replace such huge IF statements and replace them with a single hash lookup and function call:&lt;br /&gt;
&lt;br /&gt;
 hash[key] (arguments...);&lt;br /&gt;
&lt;br /&gt;
For example, consider:&lt;br /&gt;
&lt;br /&gt;
 var makeFuncString = func(c) return tolower(&amp;quot;set_&amp;quot;~c~&amp;quot;_tile&amp;quot;);&lt;br /&gt;
 var isFunc = func(f) typeof(f)=='func';&lt;br /&gt;
 var hasMethod = func(h,m) contains(h,m) and isFunc;&lt;br /&gt;
 var callIfAvailable = func(hash, method, unavailable=func{} ) {&lt;br /&gt;
  var c=hasMethod(hash,makeFuncString(m) ) or unavailable();&lt;br /&gt;
  hash[makeFuncString(m)] ();&lt;br /&gt;
 }&lt;br /&gt;
 callIfAvailable( weather_tiles,code, func {die(&amp;quot;key not found in hash or not a func&amp;quot;);} );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Initializing data structures ==&lt;br /&gt;
&lt;br /&gt;
There are some more possibilities to increase the density of your code, such as by removing redundant code or by generalizing and refactoring existing code so that it can be reused in different places (i.e. avoiding duplicate code): &lt;br /&gt;
&lt;br /&gt;
For example see weather_tile_management.nas #1000 (create_neighbours function):&lt;br /&gt;
&lt;br /&gt;
    1008 x = -40000.0; y = 40000.0;&lt;br /&gt;
    1009 setprop(lw~&amp;quot;tiles/tile[0]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1010 setprop(lw~&amp;quot;tiles/tile[0]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1011 setprop(lw~&amp;quot;tiles/tile[0]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1012 setprop(lw~&amp;quot;tiles/tile[0]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1013 setprop(lw~&amp;quot;tiles/tile[0]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1014 setprop(lw~&amp;quot;tiles/tile[0]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1015 setprop(lw~&amp;quot;tiles/tile[0]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1016&lt;br /&gt;
    1017 x = 0.0; y = 40000.0;&lt;br /&gt;
    1018 setprop(lw~&amp;quot;tiles/tile[1]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1019 setprop(lw~&amp;quot;tiles/tile[1]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1020 setprop(lw~&amp;quot;tiles/tile[1]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1021 setprop(lw~&amp;quot;tiles/tile[1]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1022 setprop(lw~&amp;quot;tiles/tile[1]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1023 setprop(lw~&amp;quot;tiles/tile[1]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1024 setprop(lw~&amp;quot;tiles/tile[1]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1025&lt;br /&gt;
    1026 x = 40000.0; y = 40000.0;&lt;br /&gt;
    1027 setprop(lw~&amp;quot;tiles/tile[2]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1028 setprop(lw~&amp;quot;tiles/tile[2]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1029 setprop(lw~&amp;quot;tiles/tile[2]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1030 setprop(lw~&amp;quot;tiles/tile[2]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1031 setprop(lw~&amp;quot;tiles/tile[2]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1032 setprop(lw~&amp;quot;tiles/tile[2]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1033 setprop(lw~&amp;quot;tiles/tile[2]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1034&lt;br /&gt;
    1035 x = -40000.0; y = 0.0;&lt;br /&gt;
    1036 setprop(lw~&amp;quot;tiles/tile[3]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1037 setprop(lw~&amp;quot;tiles/tile[3]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1038 setprop(lw~&amp;quot;tiles/tile[3]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1039 setprop(lw~&amp;quot;tiles/tile[3]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1040 setprop(lw~&amp;quot;tiles/tile[3]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1041 setprop(lw~&amp;quot;tiles/tile[3]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1042 setprop(lw~&amp;quot;tiles/tile[3]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1043&lt;br /&gt;
    1044 # this is the current tile&lt;br /&gt;
    1045 x = 0.0; y = 0.0;&lt;br /&gt;
    1046 setprop(lw~&amp;quot;tiles/tile[4]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1047 setprop(lw~&amp;quot;tiles/tile[4]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1048 setprop(lw~&amp;quot;tiles/tile[4]/generated-flag&amp;quot;,1);&lt;br /&gt;
    1049 setprop(lw~&amp;quot;tiles/tile[4]/tile-index&amp;quot;,1);&lt;br /&gt;
    1050 setprop(lw~&amp;quot;tiles/tile[4]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1051 setprop(lw~&amp;quot;tiles/tile[4]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1052 setprop(lw~&amp;quot;tiles/tile[4]/orientation-deg&amp;quot;,getprop(lw~&amp;quot;tmp/tile-orientation-deg&amp;quot;));&lt;br /&gt;
    1053&lt;br /&gt;
    1054&lt;br /&gt;
    1055 x = 40000.0; y = 0.0;&lt;br /&gt;
    1056 setprop(lw~&amp;quot;tiles/tile[5]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1057 setprop(lw~&amp;quot;tiles/tile[5]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1058 setprop(lw~&amp;quot;tiles/tile[5]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1059 setprop(lw~&amp;quot;tiles/tile[5]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1060 setprop(lw~&amp;quot;tiles/tile[5]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1061 setprop(lw~&amp;quot;tiles/tile[5]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1062 setprop(lw~&amp;quot;tiles/tile[5]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1063&lt;br /&gt;
    1064 x = -40000.0; y = -40000.0;&lt;br /&gt;
    1065 setprop(lw~&amp;quot;tiles/tile[6]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1066 setprop(lw~&amp;quot;tiles/tile[6]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1067 setprop(lw~&amp;quot;tiles/tile[6]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1068 setprop(lw~&amp;quot;tiles/tile[6]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1069 setprop(lw~&amp;quot;tiles/tile[6]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1070 setprop(lw~&amp;quot;tiles/tile[6]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1071 setprop(lw~&amp;quot;tiles/tile[6]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1072&lt;br /&gt;
    1073 x = 0.0; y = -40000.0;&lt;br /&gt;
    1074 setprop(lw~&amp;quot;tiles/tile[7]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1075 setprop(lw~&amp;quot;tiles/tile[7]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1076 setprop(lw~&amp;quot;tiles/tile[7]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1077 setprop(lw~&amp;quot;tiles/tile[7]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1078 setprop(lw~&amp;quot;tiles/tile[7]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1079 setprop(lw~&amp;quot;tiles/tile[7]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1080 setprop(lw~&amp;quot;tiles/tile[7]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1081&lt;br /&gt;
    1082 x = 40000.0; y = -40000.0;&lt;br /&gt;
    1083 setprop(lw~&amp;quot;tiles/tile[8]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1084 setprop(lw~&amp;quot;tiles/tile[8]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1085 setprop(lw~&amp;quot;tiles/tile[8]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1086 setprop(lw~&amp;quot;tiles/tile[8]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1087 setprop(lw~&amp;quot;tiles/tile[8]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1088 setprop(lw~&amp;quot;tiles/tile[8]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1089 setprop(lw~&amp;quot;tiles/tile[8]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1090 }&lt;br /&gt;
&lt;br /&gt;
At first glance, this seems like a fairly repetitive and redundant block of code, so it could probably be simplified easily:&lt;br /&gt;
&lt;br /&gt;
    var create_neighbours = func (blat, blon, alpha)        {&lt;br /&gt;
    var phi = alpha * math.pi/180.0;&lt;br /&gt;
    calc_geo(blat);&lt;br /&gt;
    var index=0;&lt;br /&gt;
    var pos = [  [-40000.0,40000.0], [0.0, 40.000], [40000.0, 40000.0], [-40000, 0],  [0,0], [40000,0], [-40000,-40000], [0,-40000], [40000,-40000] ];&lt;br /&gt;
    foreach (var p;pos) {&lt;br /&gt;
    x=p[0]; y=p[1];&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/generated-flag&amp;quot;,0);&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/tile-index&amp;quot;,-1);&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    index=index+1;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
&lt;br /&gt;
Nasal has several ways to implement an iteration.&lt;br /&gt;
&lt;br /&gt;
===for, while, foreach, and forindex loops===&lt;br /&gt;
Nasal's looping constructs are mostly C-like:&lt;br /&gt;
&lt;br /&gt;
 for(var i=0; i &amp;lt; 3; i = i+1) {&lt;br /&gt;
  # loop body&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
 while (condition) {&lt;br /&gt;
 # loop body&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The differences are that there is no do{}while(); construct, and there is a foreach, which takes a local variable name as its first argument and a vector as its second:&lt;br /&gt;
&lt;br /&gt;
  foreach(elem; list1) { doSomething(elem); }  # NOTE: the delimiter is a SEMICOLON ;&lt;br /&gt;
&lt;br /&gt;
The hash/vector index expression is an lvalue that can be assigned as well as inspected:&lt;br /&gt;
&lt;br /&gt;
  foreach(light; lights) { lightNodes[light] = propertyPath; }&lt;br /&gt;
&lt;br /&gt;
To walk through all elements of a hash, for a foreach loop on the keys of they hash.  Then you call pull up the values of the hash using the key.  Example:&lt;br /&gt;
&lt;br /&gt;
 myhash= {first: 1000, second: 250, third: 25.2 };&lt;br /&gt;
 foreach (var i; keys (myhash)) {&lt;br /&gt;
   #multiply each value by 2:&lt;br /&gt;
   myhash[i] *= 2; &lt;br /&gt;
   #print the key and new value:&lt;br /&gt;
   print (i, &amp;quot;: &amp;quot;, myhash[i]);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
There is also a &amp;quot;forindex&amp;quot;, which is like foreach except that it assigns the index of each element, instead of the value, to the loop variable.&lt;br /&gt;
&lt;br /&gt;
 forindex(i; list1) { doSomething(list1[i]); }&lt;br /&gt;
&lt;br /&gt;
Also, braceless blocks work for loops equally well:&lt;br /&gt;
&lt;br /&gt;
 var c=0;&lt;br /&gt;
 while( c&amp;lt;5 )&lt;br /&gt;
  print( c+=1 );&lt;br /&gt;
 print(&amp;quot;end of loop\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
===settimer loops===&lt;br /&gt;
Loops using &amp;lt;tt&amp;gt;while&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;foreach&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;forindex&amp;lt;/tt&amp;gt; block all of FlightGear's subsystems that run in the main thread, and can, thus, only be used for instantaneous operations that don't take too long. &lt;br /&gt;
&lt;br /&gt;
For operations that should continue over a longer period, one needs a non-blocking solution. This is done by letting functions call themselves after a timed delay: &lt;br /&gt;
&lt;br /&gt;
 var loop = func {&lt;br /&gt;
     print(&amp;quot;this line appears once every two seconds&amp;quot;);&lt;br /&gt;
     settimer(loop, 2);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 loop();        # start loop&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;settimer&amp;lt;/tt&amp;gt; function expects a ''function object'' (&amp;lt;tt&amp;gt;loop&amp;lt;/tt&amp;gt;), not a function call (&amp;lt;tt&amp;gt;loop()&amp;lt;/tt&amp;gt;) (though it is possible to make a function call return a function object--an advanced functional programming technique that you won't need to worry about if you're just getting started with Nasal). &lt;br /&gt;
&lt;br /&gt;
The fewer code FlightGear has to execute, the better, so it is desirable to run loops only when they are needed. But how does one stop a loop? A once triggered timer function can't be revoked. But one can let the loop function check an outside variable and refuse calling itself, which makes the loop chain die off:&lt;br /&gt;
&lt;br /&gt;
 var running = 1;&lt;br /&gt;
 var loop = func {&lt;br /&gt;
     if (running) {&lt;br /&gt;
         print(&amp;quot;this line appears once every two seconds&amp;quot;);&lt;br /&gt;
         settimer(loop, 2);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 loop();        # start loop ...&lt;br /&gt;
 ...&lt;br /&gt;
 running = 0;   # ... and let it die&lt;br /&gt;
&lt;br /&gt;
Unfortunately, this method is rather unreliable. What if the loop is &amp;quot;stopped&amp;quot; and a new instance immediately started again? Then the ''running'' variable would be ''1'' again, and a pending old loop call, which should really finish this chain, would happily continue. And the new loop chain would start, too, so that we would end up with two loop chains.&lt;br /&gt;
&lt;br /&gt;
This can be solved by providing each loop chain with a ''loop identifier'' and letting the function end itself if the id doesn't match the global loop-id. Self-called loop functions need to inherit the chain id. So, every time the global loop id is increased, all loop chains die, and a new one can immediately be started.&lt;br /&gt;
&lt;br /&gt;
 var loopid = 0;&lt;br /&gt;
 var loop = func(id) {&lt;br /&gt;
     id == loopid or return;           # stop here if the id doesn't match the global loop-id&lt;br /&gt;
     ...&lt;br /&gt;
     settimer(func { loop(id) }, 2);   # call self with own loop id&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 loop(loopid);       # start loop&lt;br /&gt;
 ...&lt;br /&gt;
 loopid += 1;        # this kills off all pending loops, as none can have this new identifier yet&lt;br /&gt;
 ...&lt;br /&gt;
 loop(loopid);       # start new chain; this can also be abbreviated to:  loop(loopid += 1);&lt;br /&gt;
&lt;br /&gt;
[[Nasal_scripting_language#settimer.28.29|More information about the settimer function is below]]&lt;br /&gt;
&lt;br /&gt;
== OOP - Object Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
In Nasal, objects (&amp;quot;classes&amp;quot;) are regular hashes. Self-reference and inheritance are implemented through special variables &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt;. To get a better understanding of the concept, let's start with the very basics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Hashes ===&lt;br /&gt;
&lt;br /&gt;
Hashes, also known as &amp;quot;dictionaries&amp;quot; in Python or &amp;quot;maps&amp;quot; in C++/STL are data structures that hold key/value pairs in a way that allows quick access to a value via its key.&lt;br /&gt;
&lt;br /&gt;
 var airport = {&lt;br /&gt;
     &amp;quot;LOXZ&amp;quot;: &amp;quot;Zeltweg&amp;quot;,&lt;br /&gt;
     &amp;quot;LOWI&amp;quot;: &amp;quot;Innsbruck&amp;quot;,&lt;br /&gt;
     &amp;quot;LOXL&amp;quot;: &amp;quot;Linz Hoersching&amp;quot;,     # the last comma is optional&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 print(airport[&amp;quot;LOXZ&amp;quot;]);            # prints &amp;quot;Zeltweg&amp;quot;&lt;br /&gt;
 airport[&amp;quot;LOXA&amp;quot;] = &amp;quot;Aigen&amp;quot;;         # adds LOXA to the hash&lt;br /&gt;
&lt;br /&gt;
The built-in function keys() returns a vector with the keys of the hash.  The function values() returns a vector with the values of the hash. For example:&lt;br /&gt;
&lt;br /&gt;
  debug.dump (keys(airport)); #prints ['LOXZ', 'LOWI', 'LOXL']&lt;br /&gt;
  debug.dump (values (airport)); #prints ['Zeltweg', 'Innsbruck', 'Linz Hoersching'] &lt;br /&gt;
&lt;br /&gt;
The quotes around keys can be left away in a hash definition if the key is a valid variable name or a number. This works just as well:&lt;br /&gt;
&lt;br /&gt;
 var airport = {&lt;br /&gt;
     LOXZ: &amp;quot;Zeltweg&amp;quot;,&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
There's also an alternative way to access hash members if the keys are valid variable names: &amp;lt;tt&amp;gt;airport.LOXI&amp;lt;/tt&amp;gt; can be used instead of &amp;lt;tt&amp;gt;airport[&amp;quot;LOXI&amp;quot;]&amp;lt;/tt&amp;gt;. There is a difference, though, which is described in the next section.&lt;br /&gt;
&lt;br /&gt;
Note that assigning a hash (or a vector) to another variable does never ''copy'' the contents. It only creates another reference to the same data structure. So manipulating the hash via its new name does in fact change the one, original hash.&lt;br /&gt;
&lt;br /&gt;
 var a = airport;&lt;br /&gt;
 a.LOXL = &amp;quot;Linz&amp;quot;;           # same as airport.LOXL!&lt;br /&gt;
 print(airport.LOXL);       # prints now &amp;quot;Linz&amp;quot;, not &amp;quot;Linz Hoersching&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(True copies of vectors can be made by assigning a full slice: &amp;lt;tt&amp;gt;var copy = vec[:]&amp;lt;/tt&amp;gt;. There's no such method for hashes.)&lt;br /&gt;
&lt;br /&gt;
=== Self-reference: &amp;quot;&amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt;&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
Values stored in a hash can be of any type, even of type ''function''. Member functions (&amp;quot;methods&amp;quot;) can reference their own enclosing hash via reserved keyword &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt;. This is comparable to the &amp;lt;tt&amp;gt;this&amp;lt;/tt&amp;gt; keyword in C++ classes, or the &amp;lt;tt&amp;gt;self&amp;lt;/tt&amp;gt; keyword in Python.&lt;br /&gt;
&lt;br /&gt;
 var value = &amp;quot;test&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
 var data = {&lt;br /&gt;
     value: 23,                         # scalar member variable&lt;br /&gt;
     write1: func { print(value); },    # function member&lt;br /&gt;
     write2: func { print(me.value); }, # function member&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 data.write1();     # prints &amp;quot;test&amp;quot;&lt;br /&gt;
 data.write2();     # prints 23&lt;br /&gt;
&lt;br /&gt;
The above example is already a simple form of an object. It has its own variable namespace (''data''), its own methods, and it can be passed around by-reference as one unit. Such classes are sometimes called ''singleton classes'', as they are unique, with no independent class instances. They mostly serve as a way to keep data and methods nicely encapsulated within a Nasal module. Often they contain a method for initializing, which is usually called &amp;lt;tt&amp;gt;init&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Inheritance: &amp;quot;&amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt;&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
What we learned about &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; in the last section is only half the truth. &amp;quot;me&amp;quot; doesn't only reference an object's own hash, but also one or more parent hashes. &amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt; is another reserved keyword. It denotes a vector referencing other object hashes, which are &amp;quot;inherited&amp;quot; that way.&lt;br /&gt;
&lt;br /&gt;
Please note that Nasal's currently supported form of encapsulation does not provide support for any form of data/information hiding (restricting access), i.e. all hash fields (but also all hash methods) are always publicly accessible (so there's nothing like the &amp;quot;private&amp;quot; or &amp;quot;protected&amp;quot; keywords in C++: in this sense, Nasal's inheritance mechanism can be thought of like C++ structs which are also public by default).&lt;br /&gt;
&lt;br /&gt;
The major difference being, that all members (functions and fields) are also always '''mutable''', which means that functions can modify the behavior of other functions quite easily, this also applies to the parents vector, too.&lt;br /&gt;
&lt;br /&gt;
 var parent_object = {&lt;br /&gt;
     value: 123,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var object = {&lt;br /&gt;
     parents: [parent_object],&lt;br /&gt;
     write: func { print(me.value) },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 object.write();    # prints 123&lt;br /&gt;
&lt;br /&gt;
Even though &amp;lt;tt&amp;gt;object&amp;lt;/tt&amp;gt; itself doesn't contain a member &amp;lt;tt&amp;gt;value&amp;lt;/tt&amp;gt;, it finds and uses the one of its parent object. &amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt; is a vector that can contain several parent objects. These are then searched in the order from left to right, until a matching member variable or method is found. Each of the parents can itself have parents, which are all recursively searched.&lt;br /&gt;
&lt;br /&gt;
In the section about hashes it was said that hash members can be accessed in two alternative ways, and that's also true for methods. &amp;lt;tt&amp;gt;object.write()&amp;lt;/tt&amp;gt; could also be called as &amp;lt;tt&amp;gt;object[&amp;quot;write&amp;quot;]()&amp;lt;/tt&amp;gt;. But only in the first form will members also be searched in parent hashes if not found in the base hash, whereas the second form creates an error if it's not a direct member.&lt;br /&gt;
&lt;br /&gt;
=== Creating class instances ===&lt;br /&gt;
&lt;br /&gt;
With &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt; we can implement a class object and create independent instances from that:&lt;br /&gt;
&lt;br /&gt;
 var Class = {&lt;br /&gt;
     write:     func { print(me.value); },&lt;br /&gt;
     increment: func { me.value += 1; },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var instance1 = { parents: [Class], value: 123 };&lt;br /&gt;
 var instance2 = { parents: [Class], value: 456 };&lt;br /&gt;
 &lt;br /&gt;
 instance1.write();    # prints 123&lt;br /&gt;
 instance2.write();    # prints 456&lt;br /&gt;
&lt;br /&gt;
As you can see, the two class instances are separate, independent objects, which share another object as parent -- they &amp;quot;inherit&amp;quot; from object &amp;lt;tt&amp;gt;Class&amp;lt;/tt&amp;gt;. One can now easily change members of any of these three objects. The following will redefine the parent's &amp;lt;tt&amp;gt;write&amp;lt;/tt&amp;gt; method, and all instances will automatically use this new version:&lt;br /&gt;
&lt;br /&gt;
 Class.write = func { print(&amp;quot;VALUE = &amp;quot; ~ me.value) }&lt;br /&gt;
&lt;br /&gt;
But one can also add a method to just one instance:&lt;br /&gt;
&lt;br /&gt;
 instance1.write = func { print(&amp;quot;VALUE = &amp;quot; ~ me.value) }&lt;br /&gt;
&lt;br /&gt;
Because &amp;lt;tt&amp;gt;instance1&amp;lt;/tt&amp;gt; does now have its own &amp;lt;tt&amp;gt;write&amp;lt;/tt&amp;gt; method, the parents won't be searched for one, so &amp;lt;tt&amp;gt;Class.write&amp;lt;/tt&amp;gt; is now overridden by &amp;lt;tt&amp;gt;instance1&amp;lt;/tt&amp;gt;'s own method. Nothing changed for &amp;lt;tt&amp;gt;instance2&amp;lt;/tt&amp;gt; -- it will still only find and use &amp;lt;tt&amp;gt;Class.write&amp;lt;/tt&amp;gt; via its parent.&lt;br /&gt;
&lt;br /&gt;
Note, the we couldn't create a class instance by simple assignment, because, as we learned above, this wouldn't create a separate copy of the Class object. All &amp;quot;instances&amp;quot; would reference the same hash!&lt;br /&gt;
&lt;br /&gt;
 var bad_instance1 = Class;   # bad&lt;br /&gt;
 var bad_instance2 = Class;   # bad&lt;br /&gt;
 &lt;br /&gt;
 bad_instance1.value = 123;   # sets Class.value to 123&lt;br /&gt;
 bad_instance2.value = 456;   # sets Class.value to 456&lt;br /&gt;
 &lt;br /&gt;
 bad_instance1.write();       # prints 456, not 123&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
Defining each class instance by explicitly creating a hash with parents is clumsy. It is nicer to have a function that does that for us. Then we can also use function arguments to initialize members of this instance.&lt;br /&gt;
&lt;br /&gt;
 var new_class = func(val) {&lt;br /&gt;
     return { parents: [Class], value: val };&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 var instance1 = new_class(123);&lt;br /&gt;
 var instance2 = new_class(456);&lt;br /&gt;
 &lt;br /&gt;
 instance1.write();   # prints 123&lt;br /&gt;
 instance2.write();   # prints 456&lt;br /&gt;
&lt;br /&gt;
Because the class generating function &amp;lt;tt&amp;gt;new_class()&amp;lt;/tt&amp;gt; really belongs to class &amp;lt;tt&amp;gt;Class&amp;lt;/tt&amp;gt;, it would be nicer to put it into the class hash as well. In this case we call it a class &amp;quot;constructor&amp;quot;, and as a convention, give it the name ''new''. It could have any name, though, and there could be more than one constructor.&lt;br /&gt;
&lt;br /&gt;
 var Class = {&lt;br /&gt;
     new: func(val) {&lt;br /&gt;
         return { parents: [Class], value: val };&lt;br /&gt;
     },&lt;br /&gt;
     write: func {&lt;br /&gt;
         print(&amp;quot;VALUE=&amp;quot; ~ me.value);&lt;br /&gt;
     },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var instance1 = Class.new(123);&lt;br /&gt;
 var instance2 = Class.new(456);&lt;br /&gt;
&lt;br /&gt;
As you can see, &amp;lt;tt&amp;gt;new()&amp;lt;/tt&amp;gt; doesn't return a copy of &amp;lt;tt&amp;gt;Class&amp;lt;/tt&amp;gt;, but rather a small hash that contains only a list of parents and one individual member &amp;lt;tt&amp;gt;value&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Classes aren't always as simple as in our example. Usually they contain several members, of which some may have yet to be calculated in the constructor. In that case it's easier to create a local object hash first, and to let the constructor finally return it. Such local hashes are often named &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt; (as a short reference to &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt;), or &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 var Class = {&lt;br /&gt;
     new: func(val) {&lt;br /&gt;
         var m = { parents: [Class] };&lt;br /&gt;
         m.value = val;&lt;br /&gt;
         return m;&lt;br /&gt;
     },&lt;br /&gt;
     write: func {&lt;br /&gt;
         print(&amp;quot;VALUE=&amp;quot; ~ me.value);&lt;br /&gt;
     },&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
This last example is the most frequently used form of class definitions in FlightGear-Nasal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Destructor ===&lt;br /&gt;
&lt;br /&gt;
There's no such thing in Nasal. In other languages destructors are automatically called when the class gets destroyed, so that memory and other resources that were allocated by the constructor can be freed. In Nasal that's all done by the Garbage Collector (GC), anyway. In the FlightGear context, however, there ''are'' resources that should get freed. Listeners should get removed, self-calling functions (&amp;quot;loops&amp;quot;) stopped. For that it's recommended to create a destructor function and to call that manually. Such functions are often called &amp;lt;tt&amp;gt;del&amp;lt;/tt&amp;gt;, similar to Python and to pair nicely with the three-letter constructor name &amp;lt;tt&amp;gt;new&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Memory management ===&lt;br /&gt;
&lt;br /&gt;
Finally, as you know now, Nasal, being a dynamic programming language, doesn't require or support any manual memory management, so unlike C++, you don't need to call operators like &amp;quot;new&amp;quot; or &amp;quot;delete&amp;quot; to allocate or free your memory.&lt;br /&gt;
&lt;br /&gt;
However, if you do know that you don't need a certain variable anymore, you can certainly give a hint to the built-in garbage collector to free it, by assigning a &amp;quot;nil&amp;quot; value to it. &lt;br /&gt;
&lt;br /&gt;
This can certainly pay off when using more complex data structures such as nested vectors or hashes, because it will tell the built-in garbage collector to remove all references to the corresponding symbols, so that they can be freed.&lt;br /&gt;
&lt;br /&gt;
It is also possible to make use of Nasal's delete() function to remove a symbol from a namespace (hash).&lt;br /&gt;
&lt;br /&gt;
So, if you are concerned about your script's memory requirements, using a combination of setting symbols to nil, or deleting them as appropriate, would allow you to create helper functions for freeing data structures easily.&lt;br /&gt;
&lt;br /&gt;
In addition, it is probably worth noting that this is also the only way to sanely reset an active Nasal namespace or even the whole interpreter. You need to do this in order to reload or re-initialize your code without restarting the whole FlightGear session [[Nasal_scripting_language#Managing_timers_and_listeners]].&lt;br /&gt;
&lt;br /&gt;
Obviously, you should first of all ensure that there is no more code running, this includes any registered listeners or timers, but also any others loops or recursive functions.&lt;br /&gt;
&lt;br /&gt;
Thus, if you'd like to reload a Nasal source file at run time, you should disable all running code, and then reset the corresponding namespace, too. This is to ensure that you get a clean and consistent namespace.&lt;br /&gt;
&lt;br /&gt;
Nasal provides a number of core library functions to manipulate namespaces, such as:&lt;br /&gt;
&lt;br /&gt;
* caller() - to get a strack trace of active functions currently on the Nasal stack&lt;br /&gt;
* compile() - to compile new Nasal code &amp;quot;on the fly&amp;quot;, i.e. dynamically from a string&lt;br /&gt;
* closure() - to query the lexical namespace of active functions&lt;br /&gt;
* bind() - to create new function objects&lt;br /&gt;
&lt;br /&gt;
More information is available here: http://www.plausible.org/nasal/lib.html&lt;br /&gt;
&lt;br /&gt;
If, on the other hand, you are using these data structures in some repeated fashion, it might make sense to keep the data structure itself around and simply re-use it next time (overwriting data as required), instead of always allocating/creating a new one, this is called &amp;quot;caching&amp;quot; and can pay off from a performance perspective.&lt;br /&gt;
&lt;br /&gt;
=== Multiple inheritance ===&lt;br /&gt;
&lt;br /&gt;
A class can inherit from one or more other classes. It can then access all methods and class members of all parent classes, but also override them and add additional members.&lt;br /&gt;
&lt;br /&gt;
 var A = {                                            # simple class A&lt;br /&gt;
     new: func {&lt;br /&gt;
         return { parents: [A] };&lt;br /&gt;
     },&lt;br /&gt;
     alpha: func print(&amp;quot;\tALPHA&amp;quot;),&lt;br /&gt;
     test:  func print(&amp;quot;\tthis is A.test&amp;quot;),&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var B = {                                            # simple class B&lt;br /&gt;
     new: func(v) {                                   # ... whose constructor takes an argument&lt;br /&gt;
         return { parents: [B], value: v };&lt;br /&gt;
     },&lt;br /&gt;
     bravo: func print(&amp;quot;\tBRAVO&amp;quot;),&lt;br /&gt;
     test:  func print(&amp;quot;\tthis is B.test&amp;quot;),&lt;br /&gt;
     write: func print(&amp;quot;\tmy value is: &amp;quot;, me.value),&lt;br /&gt;
 },&lt;br /&gt;
 &lt;br /&gt;
 var C = {                                            # class C that inherits ...&lt;br /&gt;
     new: func(v) {&lt;br /&gt;
         return { parents: [C, A.new(), B.new(v)] };  # ... from class A and B&lt;br /&gt;
     },&lt;br /&gt;
     charlie: func print(&amp;quot;\tCHARLIE&amp;quot;),&lt;br /&gt;
     test:    func print(&amp;quot;\tthis is C.test&amp;quot;),         # overrides A.test() and B.test()&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 print(&amp;quot;A instance&amp;quot;);&lt;br /&gt;
 var a = A.new();&lt;br /&gt;
 a.alpha();&lt;br /&gt;
 &lt;br /&gt;
 print(&amp;quot;B instance&amp;quot;);&lt;br /&gt;
 var b = B.new(123);&lt;br /&gt;
 b.bravo();&lt;br /&gt;
 b.write();&lt;br /&gt;
 &lt;br /&gt;
 print(&amp;quot;C instance&amp;quot;);&lt;br /&gt;
 var c = C.new(456);&lt;br /&gt;
 c.alpha();                        # use alpha from the A parent&lt;br /&gt;
 c.bravo();                        # use bravo from the B parent&lt;br /&gt;
 c.charlie();                      # use charlie from C itself&lt;br /&gt;
 c.test();                         # use C.test(), which overrides A.test() and B.test()&lt;br /&gt;
 c.write();&lt;br /&gt;
&lt;br /&gt;
Even if a class overrides a method of a parent with the same name, the parent's version can still be accessed via &amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt; vector.&lt;br /&gt;
&lt;br /&gt;
 c.test()               # use C.test()&lt;br /&gt;
 c.parents[0].test();   # use C.test()&lt;br /&gt;
 c.parents[1].test();   # use A.test()&lt;br /&gt;
 c.parents[2].test();   # use B.test()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== More on methods ===&lt;br /&gt;
&lt;br /&gt;
Methods are function members of a class hash. They can access other class members via the &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; variable, which is a reference to the class hash. For this reason, a method returning &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; can be used like the class itself, and one can apply further methods to the return value (this is usually called &amp;quot;method chaining&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
 var Object = {&lt;br /&gt;
     new: func(coords...) {&lt;br /&gt;
         return { parents: [Object], coords: coords };&lt;br /&gt;
     },&lt;br /&gt;
     rotate: func(angle) {&lt;br /&gt;
         # do the rotation&lt;br /&gt;
         return me;&lt;br /&gt;
     },&lt;br /&gt;
     scale: func(factor) {&lt;br /&gt;
         # do the scaling&lt;br /&gt;
         return me;&lt;br /&gt;
     },&lt;br /&gt;
     translate: func(x, y) {&lt;br /&gt;
         # do the translation&lt;br /&gt;
         return me;&lt;br /&gt;
     },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var triangle = Object.new([0, 0], [10, 0], [5, 7]);&lt;br /&gt;
 triangle.translate(-9, -4).scale(5).rotate(33).translate(9, 4);    # concatenated methods thanks to &amp;quot;me&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt;, however, is only known in the scope of the class. If a method is to be called as a listener callback or a timer function, &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; has to get wrapped in a function, so that it's stored in the function closure.&lt;br /&gt;
&lt;br /&gt;
 var Manager = {&lt;br /&gt;
     new: func {&lt;br /&gt;
         return { parents: [Manager] };&lt;br /&gt;
     },&lt;br /&gt;
     start_timers: func {  &lt;br /&gt;
         settimer(do_stuff, 5);            # BAD: there's no &amp;quot;do_stuff&amp;quot; function in the scope&lt;br /&gt;
         settimer(me.do_stuff, 5);         # BAD: function exists, but &amp;quot;me&amp;quot; won't be known&lt;br /&gt;
                                           #      when the timer function is actually executed&lt;br /&gt;
         settimer(func me.do_stuff(), 5);  # GOOD: new function object packs &amp;quot;me&amp;quot; in the closure&lt;br /&gt;
 &lt;br /&gt;
         setlistener(&amp;quot;/sim/foo&amp;quot;, func me.do_stuff());  # GOOD  (same as with timers) &lt;br /&gt;
     },         &lt;br /&gt;
     do_stuff: func {&lt;br /&gt;
         print(&amp;quot;doing stuff&amp;quot;);&lt;br /&gt;
     },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var manager = Manager.new();&lt;br /&gt;
 manager.start_timers();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Click ''[http://wiki.flightgear.org/Namespaces_and_Methods#Methods here]'' for more information.'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Exception handling ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;die()&amp;lt;/tt&amp;gt; aborts a function with an error message (this can be compared to the throw() mechanism in C++).&lt;br /&gt;
&lt;br /&gt;
 var divide = func(a, b) {&lt;br /&gt;
     if (b == 0)&lt;br /&gt;
         die(&amp;quot;division by zero&amp;quot;);&lt;br /&gt;
     return a / b;     # this line won't be reached if b == 0&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
die() is also used internally by built-in extension functions or Nasal core functions. &amp;lt;tt&amp;gt;getprop(&amp;quot;/4me&amp;quot;)&amp;lt;/tt&amp;gt;, for example, dies with an error message ''&amp;quot;name must begin with alpha or '_'&amp;quot;''. Now assume we want to write a dialog where the user can type a property path into an input field, and we display the property's value in a popup dialog. What if the user typed an invalid path and we hand that over to &amp;lt;tt&amp;gt;getprop()&amp;lt;/tt&amp;gt;? We don't want Nasal to abort our code because of that. We want to display a nice error message instead. The &amp;lt;tt&amp;gt;call()&amp;lt;/tt&amp;gt; function can catch &amp;lt;tt&amp;gt;die()&amp;lt;/tt&amp;gt; exceptions:&lt;br /&gt;
&lt;br /&gt;
 var value = getprop(property);                                    # dies if 'property' is invalid&lt;br /&gt;
 var value = call(func getprop(property), nil, var err = []);      # catches invalid-property-exception and continues&lt;br /&gt;
&lt;br /&gt;
The second line calls getprop(property) just like the first, and returns its value. But if 'property' was invalid then the &amp;lt;tt&amp;gt;call()&amp;lt;/tt&amp;gt; function catches the exception and sets the 'err' vector instead. That vector remains empty on success.&lt;br /&gt;
&lt;br /&gt;
 if (size(err))&lt;br /&gt;
     print(&amp;quot;ERROR: bad property &amp;quot;, property, &amp;quot; (&amp;quot;, err[0], &amp;quot;)&amp;quot;);   # err[0] contains the die() message&lt;br /&gt;
 else&lt;br /&gt;
     print(&amp;quot;value of &amp;quot;, property, &amp;quot; is &amp;quot;, value);&lt;br /&gt;
&lt;br /&gt;
The first argument of &amp;lt;tt&amp;gt;call()&amp;lt;/tt&amp;gt; is a function object, the second a vector of function arguments (or ''nil''), and the third a vector where the function will return a possible error. For more information on the &amp;lt;tt&amp;gt;call()&amp;lt;/tt&amp;gt; function see the [http://plausible.org/nasal/lib.html Nasal library documentation]. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;die()&amp;lt;/tt&amp;gt; doesn't really care about what its argument is. It doesn't have to be a string, and can be any variable, for example a class. This can be used to pass values through a chain of functions.&lt;br /&gt;
&lt;br /&gt;
 var Error = {                                                             # exception class&lt;br /&gt;
     new: func(msg, number) {&lt;br /&gt;
         return { parents: [Error], message: msg, number: number };&lt;br /&gt;
     },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var A = func(a) {&lt;br /&gt;
     if (a &amp;lt; 0)&lt;br /&gt;
         die(Error.new(&amp;quot;negative argument to A&amp;quot;, a));                      # throw Error&lt;br /&gt;
     return &amp;quot;A received &amp;quot; ~ a;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 var B = func(val) {&lt;br /&gt;
     var result = A(val);&lt;br /&gt;
     print(&amp;quot;B finished&amp;quot;);      # this line is not reached if A threw an exception&lt;br /&gt;
     return result;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 var value = call(B, [-4], var err = []);                                  # try B(-4)&lt;br /&gt;
 &lt;br /&gt;
 if (size(err)) {                                                          # catch (...)&lt;br /&gt;
     print(&amp;quot;ERROR: &amp;quot;, err[0].message, &amp;quot;; bad value was &amp;quot;, err[0].number);&lt;br /&gt;
     die(err[0]);                                                          # re-throw&lt;br /&gt;
 } else {&lt;br /&gt;
     print(&amp;quot;SUCCESS: &amp;quot;, value);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Listeners and Signals ==&lt;br /&gt;
&lt;br /&gt;
Listeners are callback functions that are attached to property nodes. They are triggered whenever the node is written to, or, depending on the listener type, also when children are added or removed, and when children are written to. Unlike polling loops, listeners don't have the least effect on the frame rate when they aren't triggered, which makes them preferable to monitor properties that aren't written to frequently. &lt;br /&gt;
&lt;br /&gt;
===setlistener() vs. _setlistener() ===&lt;br /&gt;
You are requested *not* to use the raw _setlistener() function, except in files in $FG_ROOT/Nasal/ when they are&lt;br /&gt;
needed immediately. Only then the raw function is required, as it doesn't rely on props.nas.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;tt&amp;gt;When listeners don't work&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Unfortunately, '''listeners don't work on so-called &amp;quot;tied&amp;quot; properties''' when the node value isn't set via property methods. (You can spot such tied properties by Ctrl-clicking the &amp;quot;.&amp;quot; entry in the property browser: they are marked with a &amp;quot;T&amp;quot;.) Most of the FDM properties are &amp;quot;tied&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Examples of properties where setlistener ''won't'' work: &lt;br /&gt;
&lt;br /&gt;
* /position/elevation-ft&lt;br /&gt;
* /ai/models/aircraft/orientation/heading-deg&lt;br /&gt;
* Any property node created as an alias&lt;br /&gt;
* Lots of others&lt;br /&gt;
&lt;br /&gt;
Before working to create a listener, always check whether a listener will work with that property node by control-clicking the &amp;quot;.&amp;quot; in property browser to put it into verbose mode, and then checking whether the property node for which you want to set up a listener is marked with a &amp;quot;T&amp;quot; or not.&lt;br /&gt;
&lt;br /&gt;
If you can't set a listener for a particular property, the alternative is to use settimer to set up a timer loop that checks the property value regularly. &lt;br /&gt;
&lt;br /&gt;
Listeners are most efficient for properties that change only occasionally.  No code is called at all during frames where the listener function is not called.  If the property value changes every frame, setting up a settimer loop with time=0 will execute every frame, just the same as setlistener would, and the settimer loop is more efficient than setting a listener. This is one reason the fact the setlistener doesn't work on certain tied and FDM properties is not a great loss.  See the section on timer loops below.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Syntax:&lt;br /&gt;
&lt;br /&gt;
 var listener_id = setlistener(&amp;lt;property&amp;gt;, &amp;lt;function&amp;gt; [, &amp;lt;startup=0&amp;gt; [, &amp;lt;runtime=1&amp;gt;]]);&lt;br /&gt;
&lt;br /&gt;
The first argument is a property node object (&amp;lt;tt&amp;gt;props.Node()&amp;lt;/tt&amp;gt; hash) or a property path. Because the node hash depends on the props.nas module being loaded, &amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; calls need to be deferred when used in an $FG_ROOT/Nasal/*.nas file, usually by calling them in a &amp;lt;tt&amp;gt;settimer(func {}, 0)&amp;lt;/tt&amp;gt; construction. To avoid that, one can use the raw &amp;lt;tt&amp;gt;_setlistener()&amp;lt;/tt&amp;gt; function directly, for which &amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; is a wrapper. The raw function does only accept node paths (e.g. &amp;quot;/sim/menubar/visibility&amp;quot;), but not props.Node() objects.&lt;br /&gt;
&lt;br /&gt;
The second argument is a function object (not a function call!). The &amp;lt;tt&amp;gt;func&amp;lt;/tt&amp;gt; keyword turns code into a function object.&lt;br /&gt;
&lt;br /&gt;
The third argument is optional. If it is non-null, then it causes the listener to be called initially. This is useful to let the callback function pick up the node value at startup.&lt;br /&gt;
&lt;br /&gt;
The fourth argument is optional, and defaults to 1. This means that the callback function will be executed whenever the property is written to, independent of the value. &lt;br /&gt;
&lt;br /&gt;
If the argument is set to 0, then the function will only get triggered if a value other than the current value is written to the node. This is important for cases where a property is written to once per frame, no matter if the value changed or not. YASim, for example, does that for /gear/gear/wow or /gear/launchbar/state.&lt;br /&gt;
So, this should be used for properties that are written to in every frame, although the written value is mostly the same. If the argument is 2, then also write access to children will get reported, as well as the creation and removal of children nodes.&lt;br /&gt;
&lt;br /&gt;
For both optional flags 0 means less calls, and 1 means more calls. The first is for startup behavior, and the second for runtime behavior.&lt;br /&gt;
&lt;br /&gt;
Here's a real-life example:&lt;br /&gt;
&lt;br /&gt;
  setlistener(&amp;quot;/gear/launchbar/state&amp;quot;, func {&lt;br /&gt;
      if (cmdarg().getValue() == &amp;quot;Engaged&amp;quot;)&lt;br /&gt;
          setprop(&amp;quot;/sim/messages/copilot&amp;quot;, &amp;quot;Engaged!&amp;quot;);&lt;br /&gt;
  }, 1, 0);&lt;br /&gt;
&lt;br /&gt;
YASim writes once per frame the string &amp;quot;Disengaged&amp;quot; to property /gear/launchbar/state. When an aircraft on deck of the aircraft carrier locks into the catapult, this changes to &amp;quot;Engaged&amp;quot;, which is then written again in every frame, until the aircraft leaves the catapult. Because the locking in is a bit difficult -- one has to target the sensitive area quite exactly --, it was desirable to get some quick feedback: a screen message that's also spoken by the Festival speech synthesis. With the args 1 and 0, this is done initially (for the unlikely case that we are locked in from the beginning), and then only when the node changes from an arbitrary value to &amp;quot;Engaged&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; returns a unique listener id on success, and &amp;lt;tt&amp;gt;nil&amp;lt;/tt&amp;gt; on error. The id is nothing else than a counter that is 0 for the first Nasal listener, 1 for the second etc. You need this id number to remove the listener. Most listeners are never removed, so that one doesn't assign the return value, but simply drop it.&lt;br /&gt;
&lt;br /&gt;
Listener callback functions can access up to four values via regular function arguments, the first two of which are property nodes in the form of a &amp;lt;tt&amp;gt;props.Node()&amp;lt;/tt&amp;gt; object hash.&lt;br /&gt;
&lt;br /&gt;
If you have set a callback function named ''myCallbackFunc'' via &amp;lt;tt&amp;gt;setlistener&amp;lt;/tt&amp;gt; (''setlistener(myNode, myCallbackFunc)''), you can use this syntax in the callback function:&lt;br /&gt;
&lt;br /&gt;
 myCallbackFunc ([&amp;lt;changed_node&amp;gt; [, &amp;lt;listened_to_node&amp;gt; [, &amp;lt;operation&amp;gt; [, &amp;lt;is_child_event&amp;gt;]]]])&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;removelistener()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Syntax:&lt;br /&gt;
&lt;br /&gt;
 var num_listeners = removelistener(&amp;lt;listener id&amp;gt;);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;removelistener()&amp;lt;/tt&amp;gt; takes one argument: the unique listener id that a &amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; call returned. It returns the number of remaining active Nasal listeners on success, &amp;lt;tt&amp;gt;nil&amp;lt;/tt&amp;gt; on error, or -1 if a listener function applies &amp;lt;tt&amp;gt;removelistener()&amp;lt;/tt&amp;gt; to itself. The fact that a listener can remove itself, can be used to implement a one-shot listener function:&lt;br /&gt;
&lt;br /&gt;
 var L = setlistener(&amp;quot;/some/property&amp;quot;, func {&lt;br /&gt;
     print(&amp;quot;I can only be triggered once.&amp;quot;);&lt;br /&gt;
     removelistener(L);&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Listener Examples ===&lt;br /&gt;
&lt;br /&gt;
The following example attaches an anonymous callback function to a &amp;quot;signal&amp;quot;. The function will be executed when FlightGear is closed.&lt;br /&gt;
&lt;br /&gt;
 setlistener(&amp;quot;/sim/signals/exit&amp;quot;, func { print(&amp;quot;bye!&amp;quot;) });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead of an anonymous function, a named function can be used as well:&lt;br /&gt;
&lt;br /&gt;
 var say_bye = func { print(&amp;quot;bye&amp;quot;) }&lt;br /&gt;
 setlistener(&amp;quot;/sim/signals/exit&amp;quot;, say_bye);&lt;br /&gt;
&lt;br /&gt;
Callback functions can, optionally, access up to four parameters which are handed over via regular function arguments. Many times none of these parameters is used at all, as in the above example.&lt;br /&gt;
&lt;br /&gt;
Most often, only the first parameter is used--which gives the node of the changed value.&lt;br /&gt;
&lt;br /&gt;
The following code attaches the monitor_course() function to a gps property, using the argument ''course'' to get the node with the changed value.&lt;br /&gt;
&lt;br /&gt;
 var monitor_course = func(course) {&lt;br /&gt;
     print(&amp;quot;Monitored course set to &amp;quot;, course.getValue());&lt;br /&gt;
 }&lt;br /&gt;
 var i = setlistener(&amp;quot;instrumentation/gps/wp/leg-course-deviation-deg&amp;quot;, monitor_course);&lt;br /&gt;
 &lt;br /&gt;
 # here the listener is active&lt;br /&gt;
 &lt;br /&gt;
 removelistener(i);                    # remove that listener again&lt;br /&gt;
&lt;br /&gt;
Here is code that accesses two arguments--the changed node and the listened-to node (these may be different when monitoring all children of a certain node)--and also shows how to monitor changes to a node including changes to children:&lt;br /&gt;
&lt;br /&gt;
 var monitor_course = func(course, flightinfo) {&lt;br /&gt;
     print(&amp;quot;One way to get the course setting: &amp;quot;, flightinfo.leg-course-deviation-deg.getValue());&lt;br /&gt;
     print(&amp;quot;Another way to get the same setting &amp;quot;, course.getValue());&lt;br /&gt;
 }&lt;br /&gt;
 var i = setlistener(&amp;quot;instrumentation/gps/wp&amp;quot;, monitor_course, 0, 2);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The function object doesn't need to be a separate, external function -- it can also be an anonymous function made directly in the &amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; call:&lt;br /&gt;
&lt;br /&gt;
 setlistener(&amp;quot;/sim/signals/exit&amp;quot;, func { print(&amp;quot;bye&amp;quot;) });    # say &amp;quot;bye&amp;quot; on exit&lt;br /&gt;
&lt;br /&gt;
Beware, however, that the contents of a function defined within the &amp;lt;tt&amp;gt;setlistener&amp;lt;/tt&amp;gt; call are not evaluated until the call is actually made. If, for instance, local variables change before the setlistener call happens, the call will reflect the current value of those variables ''at the time the callback function is called'', not the value ''at the time the listener was set''. &lt;br /&gt;
&lt;br /&gt;
For example, with this loop, the function will always return the value 10--even if mynode[1], mynode[2], mynode[3] or any of the others is the one that changed. It is because the contents of the setlistener are evaluated after the loop has completed running and at that point, i=10:&lt;br /&gt;
&lt;br /&gt;
 var output = func(number) {&lt;br /&gt;
     print(&amp;quot;mynode&amp;quot;, number, &amp;quot; has changed!&amp;quot;); #This won't work!&lt;br /&gt;
 }&lt;br /&gt;
 for(i=1; i &amp;lt;= 10; i = i+1) {&lt;br /&gt;
    var i = setlistener(&amp;quot;mynode[&amp;quot;~i~&amp;quot;]&amp;quot;, func{ output (i); });&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
You can also access the four available function properties (or just one, two, or three of them as you need) in your anonymous function. Here is an example that accesses the first value:&lt;br /&gt;
 &lt;br /&gt;
 for(i=1; i &amp;lt;= 10; i = i+1) {&lt;br /&gt;
    var i = setlistener(&amp;quot;mynode[&amp;quot;~i~&amp;quot;]&amp;quot;, func (changedNode) { print (changedNode.getPath() ~ &amp;quot; : &amp;quot; ~ changedNode.getValue()); });&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Attaching a function to a node that is specified as &amp;lt;tt&amp;gt;props.Node()&amp;lt;/tt&amp;gt; hash:&lt;br /&gt;
&lt;br /&gt;
 var node = props.globals.getNode(&amp;quot;/sim/signals/click&amp;quot;, 1);&lt;br /&gt;
 setlistener(node, func { gui.popupTip(&amp;quot;don't click here!&amp;quot;) });&lt;br /&gt;
&lt;br /&gt;
Sometimes it is desirable to call the listener function initially, so that it can pick up the node value. In the following example a listener watches the view number, and turns the HUD on in cockpit view, and off in all other views. It doesn't only do that on writing to &amp;quot;view-number&amp;quot;, but also once when the listener gets attached, thanks to the third argument &amp;quot;1&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 setlistener(&amp;quot;/sim/current-view/view-number&amp;quot;, func(n) {&lt;br /&gt;
     setprop(&amp;quot;/sim/hud/visibility[0]&amp;quot;, n.getValue() == 0);&lt;br /&gt;
 }, 1);&lt;br /&gt;
&lt;br /&gt;
There's no limit for listeners on a node. Several functions can get attached to one node, just as one function can get attached to several nodes. Listeners may write to the node they are listening to. This will not make the listener call itself causing an endless recursion.&lt;br /&gt;
&lt;br /&gt;
=== Signals ===&lt;br /&gt;
&lt;br /&gt;
In addition to &amp;quot;normal&amp;quot; nodes, there are &amp;quot;signal&amp;quot; nodes that were created solely for the purpose of having listeners attached:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/exit&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; on quitting FlightGear&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/reinit&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; right before resetting FlightGear (Shift-Esc), and to &amp;quot;false&amp;quot; afterwards&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/click&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; after a mouse click at the terrain. Hint that the geo coords for the click spot were updated and can be retrieved from /sim/input/click/{longitude-deg,latitude-deg,elevation-ft,elevation-m}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/screenshot&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; right before the screenshot is taken, and set to &amp;quot;false&amp;quot; after it. Can be used to hide and reveal dialogs etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/nasal-dir-initialized&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; after all Nasal &amp;quot;library&amp;quot; files in $FG_ROOT/Nasal/ were loaded and executed. It is only set once and can only be used to trigger listener functions that were defined in one of the Nasal files in that directory. After that signal was set&lt;br /&gt;
Nasal starts loading and executing aircraft Nasal files, and only later are &amp;lt;tt&amp;gt;settimer()&amp;lt;/tt&amp;gt; functions&lt;br /&gt;
called and the next signal is set:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/fdm-initialized&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; when then FDM has just finished its initialization&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/reinit-gui&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; when the GUI has just been reset (e.g. via Help menu). This&lt;br /&gt;
is used by the gui.Dialog class to reload Nasal-loaded XML dialogs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/frame&amp;lt;/tt&amp;gt; ... triggered at the beginning of each iteration of the main loop (a.k.a. &amp;quot;frame&amp;quot;). This is meant for debugging purposes. Normally, one would just use a settimer() with interval 0 for the same effect. The difference is that the signal is guaranteed to be raised at a defined moment, while the timer call may change when subsystems are re-ordered.&lt;br /&gt;
&lt;br /&gt;
== FlightGear extension functions ==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;cmdarg()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
cmdarg() is a mechanism to pass arguments to a nasal script (wrapped in properties) instead of &amp;quot;normal&amp;quot; function parameters. Note that cmdarg() should be primarily used in Nasal code embedded in XML files and should be considered depreciated otherwise (see [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg18361.html] and [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg18361.html]).&lt;br /&gt;
&lt;br /&gt;
cmdarg() will keep working in (joystick) XML-'''bindings''' and on the top-level of embedded Nasal scripts (i.e. dialog and animation XML files).&lt;br /&gt;
&lt;br /&gt;
As such, the cmdarg() function is primarily used for listener callbacks declared in XML markup, cmdarg() returns the listened-to property as props.Node object, so you can use it with all its methods (see $FG_ROOT/Nasal/props.nas) for example:&lt;br /&gt;
&lt;br /&gt;
  print(cmdarg().getPath(), &amp;quot; has been changed to &amp;quot;, cmdarg().getValue())&lt;br /&gt;
&lt;br /&gt;
The cmdarg() function avoids that you have to type the exact same path twice (once here and once in the setlistener() command) and it makes clear that this is the listened to property. Also, you can use all the nice props.Node methods on cmdarg() directly:&lt;br /&gt;
&lt;br /&gt;
 setlistener(&amp;quot;/gear/launchbar/state&amp;quot;, func {&lt;br /&gt;
      if (cmdarg().getValue() == &amp;quot;Engaged&amp;quot;)&lt;br /&gt;
          setprop(&amp;quot;/sim/messages/copilot&amp;quot;, &amp;quot;Engaged!&amp;quot;);&lt;br /&gt;
  }, 1, 0);&lt;br /&gt;
&lt;br /&gt;
Use of cmdarg() outside of XML-bindings won't cause an error, but (still) return the last cmdarg() property. This just won't be the listened-to property anymore, but whatever the last legitimate cmdarg() user set. Most of the time it will be the property root of a joystick binding.&lt;br /&gt;
&lt;br /&gt;
Don't make any assumptions and use cmdarg() only in one of these cases:&lt;br /&gt;
&lt;br /&gt;
* binding: returns root of this binding's property branch. Needed for accessing an axis' value:         cmdarg().getNode(&amp;quot;setting&amp;quot;).getValue()&lt;br /&gt;
&lt;br /&gt;
* dialog xml files: returns root of that file's property branch in memory. This can be used to let embedded Nasal change the dialog (e.g. clear and build lists) before the final layout is decided&lt;br /&gt;
&lt;br /&gt;
* animation xml files: returns root of this model's place in /ai/models/ when used as AI/MP model. Examples:       /ai/models/multiplayer[3], /ai/models/tanker[1], etc. [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg14164.html]&lt;br /&gt;
&lt;br /&gt;
* AI aircraft XML files&lt;br /&gt;
&lt;br /&gt;
* remotely invoking Nasal code by setting properties using the built-in telnet daemon (RPC) [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg00150.html [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg00336.html].&lt;br /&gt;
&lt;br /&gt;
'''In all cases, the cmdarg() call must not be delayed until later using settimer() or setlistener(). Because later it'll again return some unrelated property!&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;fgcommand()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Runs an internal &amp;quot;fgcommand&amp;quot;, see $FG_ROOT/Docs/README.commands for a list of available commands: http://gitorious.org/fg/fgdata/blobs/master/Docs/README.commands&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;print()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Concatenates an arbitrary number of arguments to one string, appends a new-line, and prints it to the terminal. Returns the number of printed characters.&lt;br /&gt;
&lt;br /&gt;
 print(&amp;quot;Just&amp;quot;, &amp;quot; a &amp;quot;, &amp;quot;test&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;getprop()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Returns the node value for a given path, or &amp;lt;tt&amp;gt;nil&amp;lt;/tt&amp;gt; if the node doesn't exist or hasn't been initialized yet. &lt;br /&gt;
&lt;br /&gt;
 getprop(&amp;lt;path&amp;gt;);&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 print(&amp;quot;The frame rate is &amp;quot;, getprop(&amp;quot;/sim/frame-rate&amp;quot;), &amp;quot; FPS&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;setprop()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Sets a property value for a given node path string. Always returns nil.&lt;br /&gt;
&lt;br /&gt;
 setprop(&amp;lt;path&amp;gt; [, &amp;lt;path&amp;gt;, [...]], &amp;lt;value&amp;gt;);&lt;br /&gt;
&lt;br /&gt;
All arguments but the last are concatenated to a path string, with a slash (/) inserted between each element. The last value is written to the respective node. If the node isn't writable, then an error message is printed to the console.&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;tt&amp;gt;setprop()&amp;lt;/tt&amp;gt; concatenates a list of input arguments by means of inserting a &amp;quot;/&amp;quot; in between. That is nice for properties, as this slash is part of the tree. However, when one wants to make use of indices, like [0], one has to concatenate by hand (using &amp;quot;~&amp;quot;) ''inside'' one part of the string argument list. An example is:&lt;br /&gt;
&lt;br /&gt;
  var i = 4;&lt;br /&gt;
  setprop(&amp;quot;instrumentation&amp;quot;,&amp;quot;cdu&amp;quot;,&amp;quot;page[&amp;quot;~i~&amp;quot;]&amp;quot;,&amp;quot;title&amp;quot;,&amp;quot;MENU&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This results in instrumentation/cdu/page[4]/title = 'MENU' (string)&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
 setprop(&amp;quot;/sim/current-view/view-number&amp;quot;, 2);&lt;br /&gt;
 setprop(&amp;quot;/controls&amp;quot;, &amp;quot;engines/engine[0]&amp;quot;, &amp;quot;reverser&amp;quot;, 1);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Erasing a property from the property tree''': a property that has been created, for example through &amp;lt;tt&amp;gt;setprop()&amp;lt;/tt&amp;gt; can be erased via&lt;br /&gt;
&lt;br /&gt;
  props.globals.getNode(&amp;quot;foo/bar&amp;quot;).remove(); 		# take out the complete node&lt;br /&gt;
  props.globals.getNode(&amp;quot;/foo&amp;quot;).removeChild(&amp;quot;bar&amp;quot;); 	# take out a certain child node&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;settimer()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Runs a function after a given simulation time (default) or real time in seconds.&lt;br /&gt;
&lt;br /&gt;
 settimer(&amp;lt;function&amp;gt;, &amp;lt;time&amp;gt; [, &amp;lt;realtime=0&amp;gt;]);&lt;br /&gt;
&lt;br /&gt;
The first object is a function object (ie, &amp;quot;func { ... }&amp;quot;).  Note that this is different from a function call (ie, &amp;quot;func ( ... )&amp;quot;). If you don't understand what this means, just remember to always enclose the first argument in any call to settimer with the word &amp;quot;func&amp;quot; and braces &amp;quot;{ }&amp;quot;, and it will always work. For instance, if you want print the words &amp;quot;My result&amp;quot; in five seconds, use this code:&lt;br /&gt;
&lt;br /&gt;
 settimer ( func { print ( &amp;quot;My result&amp;quot;); }, 5);&lt;br /&gt;
&lt;br /&gt;
Inside the braces of the func object you can put any valid Nasal code, including a function call.  In fact, if you want to call a function with certain values as arguments, the way to do it is to turn it into a function object by enclosing it with a func{}, for example:&lt;br /&gt;
&lt;br /&gt;
 myarg1=&amp;quot;My favorite string&amp;quot;;&lt;br /&gt;
 myarg2=432;&lt;br /&gt;
 settimer ( func { myfunction ( myarg1, myarg2); }, 25);&lt;br /&gt;
&lt;br /&gt;
The third argument is optional and defaults to 0, which lets the time argument be interpreted as &amp;quot;seconds simulation time&amp;quot;. In this case the timer doesn't run when FlightGear is paused. For user interaction purposes (measuring key press time, displaying popups, etc.) one usually prefers real time.&lt;br /&gt;
&lt;br /&gt;
 # simulation time example&lt;br /&gt;
 var copilot_annoyed = func { setprop(&amp;quot;/sim/messages/copilot&amp;quot;, &amp;quot;Stop it! Immediately!&amp;quot;) }&lt;br /&gt;
 settimer(copilot_annoyed, 10);&lt;br /&gt;
&lt;br /&gt;
 # real time example&lt;br /&gt;
 var popdown = func ( tipArg ) { &lt;br /&gt;
  fgcommand(&amp;quot;dialog-close&amp;quot;, tipArg); &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 var selfStatusPopupTip = func (label, delay = 10, override = nil) {	&lt;br /&gt;
    var tmpl = props.Node.new({&lt;br /&gt;
            name : &amp;quot;PopTipSelf&amp;quot;, modal : 0, layout : &amp;quot;hbox&amp;quot;,&lt;br /&gt;
            y: 140,&lt;br /&gt;
            text : { label : label, padding : 6 }&lt;br /&gt;
    });&lt;br /&gt;
    if (override != nil) tmpl.setValues(override);&lt;br /&gt;
    &lt;br /&gt;
    popdown(tipArgSelf);&lt;br /&gt;
    fgcommand(&amp;quot;dialog-new&amp;quot;, tmpl);&lt;br /&gt;
    fgcommand(&amp;quot;dialog-show&amp;quot;, tipArgSelf);&lt;br /&gt;
 &lt;br /&gt;
    currTimerSelf += 1;&lt;br /&gt;
    var thisTimerSelf = currTimerSelf;&lt;br /&gt;
 &lt;br /&gt;
    # Final argument 1 is a flag to use &amp;quot;real&amp;quot; time, not simulated time&lt;br /&gt;
    settimer(func { if(currTimerSelf == thisTimerSelf) { popdown(tipArgSelf) } }, delay, 1);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
[[Nasal_scripting_language#settimer_loops|More information about best practices for using the settimer function to create loops in Nasal is elsewhere on this page.]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;systime()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Returns epoch time (time since 1972/01/01 00:00) in seconds as a floating point number with high resolution. This is useful for benchmarking purposes.&lt;br /&gt;
&lt;br /&gt;
  #benchmarking example:&lt;br /&gt;
  var start = systime();&lt;br /&gt;
  how_fast_am_I(123);&lt;br /&gt;
  var end = systime();&lt;br /&gt;
  print(&amp;quot;took &amp;quot;, end - start, &amp;quot; seconds&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;carttogeod()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Converts cartesian coordinates x/y/z to geodetic coordinates lat/lon/alt, which are returned as a vector. Units are degree and meter.&lt;br /&gt;
&lt;br /&gt;
 var geod = carttogeod(-2737504, -4264101, 3862172);&lt;br /&gt;
 print(&amp;quot;lat=&amp;quot;, geod[0], &amp;quot; lon=&amp;quot;, geod[1], &amp;quot; alt=&amp;quot;, geod[2]);&lt;br /&gt;
 &lt;br /&gt;
 # outputs&lt;br /&gt;
 lat=37.49999782141546 lon=-122.6999914632327 alt=998.6042055172776&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;geodtocart()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Converts geodetic coordinates lat/lon/alt to cartesian coordinates x/y/z. Units are degree and meter.&lt;br /&gt;
&lt;br /&gt;
 var cart = geodtocart(37.5, -122.7, 1000); # lat/lon/alt(m)&lt;br /&gt;
 print(&amp;quot;x=&amp;quot;, cart[0], &amp;quot; y=&amp;quot;, cart[1], &amp;quot; z=&amp;quot;, cart[2]);&lt;br /&gt;
 &lt;br /&gt;
 # outputs&lt;br /&gt;
 x=-2737504.667684828 y=-4264101.900993474 z=3862172.834656495&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;geodinfo()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Returns information about geodetic coordinates. Takes two arguments: lat, lon (in degree) and returns a vector with two entries, or nil if no information could be obtained because the terrain tile wasn't loaded. The first entry is the elevation (in meters) for the given point, and the second is a hash with information about the assigned material, or nil if there was no material information available, because there is, for instance, an untextured building at that spot or the scenery tile is not loaded.&lt;br /&gt;
&lt;br /&gt;
 var lat = getprop(&amp;quot;/position/latitude-deg&amp;quot;);&lt;br /&gt;
 var lon = getprop(&amp;quot;/position/longitude-deg&amp;quot;);&lt;br /&gt;
 var info = geodinfo(lat, lon);&lt;br /&gt;
 &lt;br /&gt;
 if (info != nil) {&lt;br /&gt;
     print(&amp;quot;the terrain under the aircraft is at elevation &amp;quot;, info[0], &amp;quot; m&amp;quot;);&lt;br /&gt;
     if (info[1] != nil)&lt;br /&gt;
         print(&amp;quot;and it is &amp;quot;, info[1].solid ? &amp;quot;solid ground&amp;quot; : &amp;quot;covered by water&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A full data set looks like this:&lt;br /&gt;
&lt;br /&gt;
 debug.dump(geodinfo(lat, lon));&lt;br /&gt;
 &lt;br /&gt;
 # outputs&lt;br /&gt;
 [ 106.9892101062052, { light_coverage : 0, bumpiness : 0.5999999999999999, load_resistance : 1e+30,&lt;br /&gt;
 solid : 0,  names : [ &amp;quot;Lake&amp;quot;, &amp;quot;Pond&amp;quot;, &amp;quot;Reservoir&amp;quot;, &amp;quot;Stream&amp;quot;, &amp;quot;Canal&amp;quot; ], friction_factor : 1, &lt;br /&gt;
 rolling_friction : 1.5 } ]&lt;br /&gt;
&lt;br /&gt;
Note that geodinfo is a *very* CPU intensive operation, particularly in FG 2.4.0 and earlier, so use sparingly ([http://flightgear.org/forums/viewtopic.php?f=4&amp;amp;p=135044#p135044 discussion here]).&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;parsexml()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
This function is an interface to the built-in [http://expat.sourceforge.net/ Expat XML parser]. It takes up to five arguments. The first is a mandatory absolute path to an XML file, the remaining four are optional callback functions, each of which can be nil (which is also the default value).&lt;br /&gt;
&lt;br /&gt;
 var ret = parsexml(&amp;lt;path&amp;gt; [, &amp;lt;start-elem&amp;gt; [, &amp;lt;end-elem&amp;gt; [, &amp;lt;data&amp;gt; [, &amp;lt;pi&amp;gt; ]]]]);&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;start-elem&amp;gt;  ... called for every starting tag with two arguments: the tag name, and an attribute hash&lt;br /&gt;
 &amp;lt;end-elem&amp;gt;    ... called for every ending tag with one argument: the tag name&lt;br /&gt;
 &amp;lt;data&amp;gt;        ... called for every piece of data with one argument: the data string&lt;br /&gt;
 &amp;lt;pi&amp;gt;          ... called for every &amp;quot;processing information&amp;quot; with two args: target and data string&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;ret&amp;gt;         ... the return value is nil on error, and the &amp;lt;path&amp;gt; otherwise&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 var start = func(name, attr) {&lt;br /&gt;
     print(&amp;quot;starting tag &amp;quot;, name);&lt;br /&gt;
     foreach (var a; keys(attr))&lt;br /&gt;
         print(&amp;quot;\twith attribute &amp;quot;, a, &amp;quot;=&amp;quot;, attr[a]);&lt;br /&gt;
 }&lt;br /&gt;
 var end = func(name) { print(&amp;quot;ending tag &amp;quot;, name) }&lt;br /&gt;
 var data = func(data) { print(&amp;quot;data=&amp;quot;, data) }&lt;br /&gt;
 var pi = func(target, data) { print(&amp;quot;processing instruction: target=&amp;quot;, target, &amp;quot; data=&amp;quot;, data) }&lt;br /&gt;
 parsexml(&amp;quot;/tmp/foo.xml&amp;quot;, start, end, data, pi);&lt;br /&gt;
&lt;br /&gt;
=== airportinfo() ===&lt;br /&gt;
Function for retrieval of airport/runway information.&lt;br /&gt;
Usage:&lt;br /&gt;
&lt;br /&gt;
  var apt = airportinfo(&amp;quot;KHAF&amp;quot;);   # get info about KHAF&lt;br /&gt;
  var apt = airportinfo(lat, lon); # get info about apt closest to lat/lon&lt;br /&gt;
  var apt = airportinfo();         # get info about apt closest to aircraft  &lt;br /&gt;
&lt;br /&gt;
The command debug.dump(airportinfo(&amp;quot;KHAF&amp;quot;)) outputs this:&lt;br /&gt;
&lt;br /&gt;
  { lon : -122.4962626410256, lat : 37.51343502564102, has_metar : 0,&lt;br /&gt;
  runways : { 12 : { stopway2 : 0, threshold1 : 232.5624,&lt;br /&gt;
  lon : -122.5010889999999, lat : 37.513831, stopway1 : 0, width : 45.72,&lt;br /&gt;
  threshold2 : 232.5624, heading : 138.1199999999999, length : 1523.0856 } },&lt;br /&gt;
  elevation : 20.42159999999999, id : &amp;quot;KHAF&amp;quot;, name : &amp;quot;Half Moon Bay&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
That is: a hash with elements lat/lon/elev/id/name/has_metar for the&lt;br /&gt;
airport, and a hash with runways, each of which consists of lat/lon/&lt;br /&gt;
/length/width/heading/threshold[12]/stopway[12]. Only one side of each&lt;br /&gt;
runway is listed -- the other can easily be deduced.&lt;br /&gt;
&lt;br /&gt;
==Built-in functions==&lt;br /&gt;
&lt;br /&gt;
===sort(vector, function)===&lt;br /&gt;
Creates a new vector containing the elements in the input vector sorted in ascending order according to the rule given by function, which takes two arguments (elements of the input vector) and should return less than zero, zero, or greater than zero if the first argument is, respectively, less than, equal to, or greater than the second argument. Despite being implemented with ANSI C qsort(), the sort is stable; &amp;quot;equal&amp;quot; elements in the output vector will appear in the same relative order as they do in the input.&lt;br /&gt;
&lt;br /&gt;
Because you can define the sort function, sort allows you to create a list of keys sorting a hash by any criterion--by key, value, or (if, for instance the hash values are hashes themselves) any subvalue.&lt;br /&gt;
&lt;br /&gt;
 vec = [100,24,45];&lt;br /&gt;
 sortvec = sort (vec, func (a,b) cmp (a,b));&lt;br /&gt;
 debug.dump (sortvec); #output is [24,45,100]&lt;br /&gt;
&lt;br /&gt;
Here is an example of how to output the contents of a hash in sorted order.  Note that the function does not actually sort the hash but returns a list of the hash keys in sorted order.&lt;br /&gt;
&lt;br /&gt;
 var airport = {&lt;br /&gt;
   &amp;quot;LOXZ&amp;quot;: &amp;quot;Zeltweg&amp;quot;,&lt;br /&gt;
   &amp;quot;LOWI&amp;quot;: &amp;quot;Innsbruck&amp;quot;,&lt;br /&gt;
   &amp;quot;LOXL&amp;quot;: &amp;quot;Linz Hoersching&amp;quot;,     # the last comma is optional&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var sortedkeys= sort (keys(airport), func (a,b) cmp (airport[a], airport[b]));&lt;br /&gt;
 &lt;br /&gt;
 foreach (var i; sortedkeys) &lt;br /&gt;
  print (i, &amp;quot;: &amp;quot;, airport[i]);&lt;br /&gt;
&lt;br /&gt;
The output is:&lt;br /&gt;
&lt;br /&gt;
   LOWI: Innsbruck&lt;br /&gt;
   LOXL: Linz Hoersching&lt;br /&gt;
   LOXZ: Zeltweg  &lt;br /&gt;
&lt;br /&gt;
If the hash values are themselves hashes, sorting by any of the subvalues is possible.  For example:&lt;br /&gt;
&lt;br /&gt;
 var airport = {&lt;br /&gt;
    &amp;quot;LOXZ&amp;quot;: {city: &amp;quot;Zeltweg&amp;quot;, altitude_m: 1300 },&lt;br /&gt;
    &amp;quot;LOWI&amp;quot;: {city: &amp;quot;Innsbruck&amp;quot;, altitude_m: 2312 }, &lt;br /&gt;
    &amp;quot;LOXL&amp;quot;: {city: &amp;quot;Linz Hoersching&amp;quot;, altitude_m: 1932 },&lt;br /&gt;
 };&lt;br /&gt;
  &lt;br /&gt;
 #return a list of the hash keys sorted by altitude_m&lt;br /&gt;
 var sortedkeys= sort (keys(airport), func (a,b) airport[a].altitude_m - airport[b].altitude_m);&lt;br /&gt;
  &lt;br /&gt;
 foreach (var i; sortedkeys) &lt;br /&gt;
  print (i, &amp;quot;: &amp;quot;, airport[i].city, &amp;quot;, &amp;quot;, airport[i].altitude_m);&lt;br /&gt;
&lt;br /&gt;
Note that ''sort'' will return errors, and in FG 2.4.0 may even stop working, if the sort function you provide returns errors.  A common cause of this is if your sort vector contains both string and numeric values.  The cmp function will return an error for numeric values, and arithmetic operations you may use to sort numeric values will return errors if performed on a string.  The error in these cases is typically &amp;quot;function/method call on uncallable object&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Other useful built-in functions ===&lt;br /&gt;
&lt;br /&gt;
Other basic built-in Nasal functions such as append, setsize, subvec, typeof, contains, delete, int, num, keys, pop, size, streq, cmp, substr, sprintf, find, split, rand, call, die, bind, math.sin, math.pi, math.exp, math.ln math.e, io.read, io.write, regex.exec, and others of that sort, [http://www.plausible.org/nasal/lib.html are detailed in this external document].&lt;br /&gt;
&lt;br /&gt;
=== Useful functions in the Nasal directory ===&lt;br /&gt;
Other functions are available in the Nasal files found in the Nasal directory of a FlightGear install.  Simply open those Nasal files in text editor to see what is inside.  Reference those functions by putting the filename in front of the function, method, variable, or object you wish to use.  For instance, to use the method Coord.new() in the file geo.nas, you simply write:&lt;br /&gt;
&lt;br /&gt;
 geo.Coord.new()&lt;br /&gt;
&lt;br /&gt;
=== Distance calculations ===&lt;br /&gt;
&lt;br /&gt;
To calculate the distance between two points (in two different ways):&lt;br /&gt;
 # mylat1, mylong1, mylat2, mylong2 are lat &amp;amp; long in degrees &lt;br /&gt;
 # myalt1 &amp;amp; myalt2 are altitude in meters&lt;br /&gt;
 &lt;br /&gt;
 var GeoCoord1 = geo.Coord.new();&lt;br /&gt;
 GeoCoord1.set_latlon(mylat1, mylong1,myalt1);&lt;br /&gt;
 &lt;br /&gt;
 var GeoCoord2 = geo.Coord.new();&lt;br /&gt;
 GeoCoord2.set_latlon(mylat2, mylong2, myalt2);&lt;br /&gt;
 &lt;br /&gt;
 var directDistance = GeoCoord1.direct_distance_to(GeoCoord2);&lt;br /&gt;
 var surfaceDistance = GeoCoord1.distance_to(GeoCoord2);&lt;br /&gt;
&lt;br /&gt;
The results are distances in meters.&lt;br /&gt;
&lt;br /&gt;
* distance_to - returns distance in meters along Earth curvature, ignoring altitudes; useful for map distance&lt;br /&gt;
* direct_distance_to - returns distance in meters direct; considers altitude, but cuts through Earth surface&lt;br /&gt;
&lt;br /&gt;
=== Other useful geographical functions ===&lt;br /&gt;
Other useful geographical functions are found in geo.nas (in the FlightGear/data/Nasal directory of a FlightGear installation). geo.nas also includes documentation/explanation of the functions available.&lt;br /&gt;
&lt;br /&gt;
==Developing and debugging in Nasal==&lt;br /&gt;
===Developing Nasal code===&lt;br /&gt;
Because code in the Nasal directory is parsed only at Flightgear startup, testing and debugging Nasal code can by slow and difficult.&lt;br /&gt;
&lt;br /&gt;
Flightgear provides a couple of ways to work around this issue:&lt;br /&gt;
&lt;br /&gt;
====Nasal Console====&lt;br /&gt;
&lt;br /&gt;
The Nasal Console is available in Flightgear's menu (Debug/Nasal Console).  Selecting this menu opens a Nasal Console dialog.&lt;br /&gt;
&lt;br /&gt;
This dialog has several tabs, of which each can hold separate Nasal code snippets, all of which are saved on exit&lt;br /&gt;
and reloaded next time. This is useful for little tests, or for executing code for which writing a key binding is just too much&lt;br /&gt;
work, such as &amp;quot;props.dump(props.globals)&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
If you want to add more tabs (radio buttons in the Nasal Console dialog) to hold more code samples, just add more &amp;amp;lt;code&amp;amp;gt; nodes to autosave.xml.&lt;br /&gt;
&lt;br /&gt;
====Loading/reloading Nasal code without re-starting Flightgear====&lt;br /&gt;
A common problem in testing and debugging Nasal programs is that each testing step requires stopping and re-starting Flightgear, a slow process.&lt;br /&gt;
&lt;br /&gt;
Below is described a technique for loading and executing a Nasal file while Flightgear is running.  Flightgear will parse the file, display any errors in the Flightgear console window, and then execute the code as usual.&lt;br /&gt;
&lt;br /&gt;
Using this technique, you can start Flightgear, load the Nasal code you want to test observe any errors or test functionality as you wish, make changes to the Nasal file, reload it to observe parse errors or change in functionality, and so on to repeatedly and quickly run through the change/load/parse/test cycle without needing to re-start Flightgear each time.&lt;br /&gt;
&lt;br /&gt;
The key to this technique is the function io.load_nasal(), which loads a nasal file into a nasal namespace. &lt;br /&gt;
&lt;br /&gt;
Step-by-step instructions showing how to use this technique to load, parse, and test a Nasal file while Flightgear is running:&lt;br /&gt;
&lt;br /&gt;
=====Create the Nasal file to test=====&lt;br /&gt;
Create a text file named $FG_ROOT/foo/test.nas with this text:&lt;br /&gt;
  &lt;br /&gt;
  print(&amp;quot;hi!&amp;quot;);&lt;br /&gt;
  var msg=&amp;quot;My message.&amp;quot;;&lt;br /&gt;
  var hello = func { print(&amp;quot;I'm the test.hello() function&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
Notes: You can create the file in any directory you wish, as long as Nasal can read the directory--but the file IOrules in the Nasal directory restricts which directories Nasal may read and write from.  &lt;br /&gt;
&lt;br /&gt;
You can give the file any name and extension you wish, though it is generally most convenient to use the .nas extension with Nasal files.&lt;br /&gt;
&lt;br /&gt;
=====Load the file and test=====&lt;br /&gt;
Start Flightgear.  You can import the file above into Flightgear by typing the following into the Nasal Console dialog and executing the code:&lt;br /&gt;
&lt;br /&gt;
  io.load_nasal(getprop(&amp;quot;/sim/fg-root&amp;quot;) ~ &amp;quot;/foo/test.nas&amp;quot;, &amp;quot;example&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
getprop(&amp;quot;/sim/fg-root&amp;quot;) gets the root directory of the FlightGear installation, ~ &amp;quot;/foo/test.nas&amp;quot; appends the directory and filename you created.  The final variable &amp;quot;example&amp;quot; tells the namespace to load for the Nasal file.&lt;br /&gt;
&lt;br /&gt;
You'll see the message &amp;quot;hi!&amp;quot; on the terminal, and have function &amp;quot;example.hello()&amp;quot; immediately available. You can, for instance, type &amp;quot;example.hello();&amp;quot; into one of the Nasal console windows and press &amp;quot;Execute&amp;quot; to see the results; similarly you could execute &amp;quot;print (example.msg);&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
If you find errors or want to make changes, simply make them in your text editor, save the file, and execute the io.load_nasal() command again in the Nasal Console to re-load the file with changes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It's worth noting that Nasal code embedded in XML GUI dialog files can be reloaded by using the &amp;quot;debug&amp;quot; menu (&amp;quot;reload GUI&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
You may also want to check out the remarks on [[Nasal_scripting_language#Memory_management|Memory management]].&lt;br /&gt;
&lt;br /&gt;
==== Managing timers and listeners ====&lt;br /&gt;
&lt;br /&gt;
Note: If your Nasal program sets listeners, timer loops, and so on, they will remain set even when the code is reloaded, and reloading the code will set additional listeners and timer loops.  &lt;br /&gt;
&lt;br /&gt;
This can lead to extremely slow framerates and unexpected behavior.  For timers you can avoid this problem by using the loopid method (described above); for listeners you can create a function to destroy all timers your Nasal program creates, and call that function before reloading the program.  (And cleaning up timer loops and listeners is a best practice for creating Nasal programs in Flightgear regardless.)&lt;br /&gt;
&lt;br /&gt;
The same problem may occur while resetting or re-initializing parts of FlightGear if your code isn't prepared for this. And obviously this applies in particular also to any worker threads you may have started, too!&lt;br /&gt;
&lt;br /&gt;
For complex Nasal scripts with many timers and listeners, it is therefore generally a very good idea to implement special callbacks so that your scripts can respond to the most important simulator &amp;quot;signals&amp;quot;, this can be achieved by registering script-specific listeners to signals like &amp;quot;reinit&amp;quot; or &amp;quot;freeze&amp;quot; (pause): the corresponding callbacks can then suspend or re-initialize the Nasal code by suspending listeners and timers. Following this practice helps ensure that your code will behave properly even during simulator resets.&lt;br /&gt;
&lt;br /&gt;
In other words, it makes sense to provide a separate high-level controller routine to look for important simulator events and then pause or re-initialize your main Nasal code as required.&lt;br /&gt;
&lt;br /&gt;
If you are using [[Nasal_scripting_language#System-wide_Nasal_code|System-wide Nasal modules]], you should register listeners to properly re-initialize and clean up your Nasal code.&lt;br /&gt;
&lt;br /&gt;
In its simplest form, this could look like this:&lt;br /&gt;
&lt;br /&gt;
 var cleanup = func {}&lt;br /&gt;
 setlistener(&amp;quot;/sim/signals/reinit&amp;quot;, cleanup);&lt;br /&gt;
&lt;br /&gt;
This will invoke your &amp;quot;cleanup&amp;quot; function, whenever the &amp;quot;reinit&amp;quot; signal is set by the FlighGear core.&lt;br /&gt;
&lt;br /&gt;
Obviously, you now need to populare your cleanup function with some code, too.&lt;br /&gt;
&lt;br /&gt;
One of the easiest ways to do this, is removing all listeners/timers manually here, i.e. by adding calls to removelistener():&lt;br /&gt;
&lt;br /&gt;
 var cleanup = func {&lt;br /&gt;
  removelistener(id);&lt;br /&gt;
  removelistener(id);&lt;br /&gt;
  removelistener(id);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This would ensure that the corresponding listeners would be removed once the signal is triggered.&lt;br /&gt;
&lt;br /&gt;
On the other hand, you could just as well use a vector of listener IDs here, and then use a Nasal foreach loop:&lt;br /&gt;
&lt;br /&gt;
 var cleanup = func(id_list) {&lt;br /&gt;
  foreach(var id; id_list)&lt;br /&gt;
   removelistener(id);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Obviously, this would require that you maintain a list of active listeners, too - so that you can actually pass a list of IDs to the cleanup function.&lt;br /&gt;
&lt;br /&gt;
This is one of those things that can be easily done in Nasal, too - just by introducing a little helper wrapper:&lt;br /&gt;
&lt;br /&gt;
 var id_list=[];&lt;br /&gt;
 var store_listener = func(id) append(id_list,id);&lt;br /&gt;
&lt;br /&gt;
The only thing required here, would be replacing/wrapping the conventional &amp;quot;setlistener&amp;quot; call with calls to your helper:&lt;br /&gt;
&lt;br /&gt;
 store_listener( setlistener(&amp;quot;/sim/foo&amp;quot;) );&lt;br /&gt;
 store_listener( setlistener(&amp;quot;/foo/bar&amp;quot;) );&lt;br /&gt;
&lt;br /&gt;
If you were to do this consistently across all your Nasal code, you'd end up with a high level way to manage all your registered listeners centrally.&lt;br /&gt;
&lt;br /&gt;
Now, you'll probably have noticed that it would make sense to consider wrapping all these helpers and variables inside an enclosing helper class, this can be accomplished in Nasal using a hash. This would enable you to to implement everything neatly organized in an object and use RAII-like patterns to manage Nasal resources like timers, listeners and even threads.&lt;br /&gt;
&lt;br /&gt;
===Debugging===&lt;br /&gt;
The file debug.nas, included in the Nasal directory of the Flightgear distribution, has several functions useful for debugging Nasal code.  These functions are available to any Nasal program or code executed by Flightgear.&lt;br /&gt;
&lt;br /&gt;
Aside from those listed below, several other useful debugging functions are found in debug.nas; see the debug.nas file for the list of functions and explanation.&lt;br /&gt;
&lt;br /&gt;
Note that the debug module makes extensive use of ANSI terminal color codes.  These create colored output on Linux/Unix systems but on other systems they may add numerous visible control codes.  To turn off the color codes, go to the internal property tree and set&lt;br /&gt;
&lt;br /&gt;
 /sim/startup/terminal-ansi-colors=0&lt;br /&gt;
&lt;br /&gt;
Or within a Nasal program:&lt;br /&gt;
&lt;br /&gt;
 setprop (&amp;quot;/sim/startup/terminal-ansi-colors&amp;quot;,0);&lt;br /&gt;
&lt;br /&gt;
====debug.dump====&lt;br /&gt;
 debug.dump([&amp;lt;variable&amp;gt;])             ... dumps full contents of variable or of local variables if none given&lt;br /&gt;
 &lt;br /&gt;
The function debug.dump() dumps the contents of the given variable to the console. On Unix/Linux this is done with some syntax coloring. For example, these lines&lt;br /&gt;
&lt;br /&gt;
  var as = props.globals.getNode(&amp;quot;/velocities/airspeed-kt&amp;quot;, 1);&lt;br /&gt;
  debug.dump(as);&lt;br /&gt;
&lt;br /&gt;
would output&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/velocities/airspeed-kt=1.021376474393101 (DOUBLE; T)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;T&amp;quot; means that it's a &amp;quot;tied&amp;quot; property. The same letters are used here as in the property-browser. The angle brackets seem superfluous, but are useful because debug.dump() also outputs compound data types, such as vectors and hashes. For example:&lt;br /&gt;
&lt;br /&gt;
  var as = props.globals.getNode(&amp;quot;/velocities/airspeed-kt&amp;quot;, 1);&lt;br /&gt;
  var ac = props.globals.getNode(&amp;quot;/sim/aircraft&amp;quot;, 1);&lt;br /&gt;
  var nodes = [as, ac];&lt;br /&gt;
  var hash = { airspeed_node: as, aircraft_name: ac, all_nodes: nodes };&lt;br /&gt;
  debug.dump(hash);&lt;br /&gt;
&lt;br /&gt;
yields:&lt;br /&gt;
&lt;br /&gt;
  { all_nodes : [ &amp;lt;/velocities/airspeed-kt=1.021376474393101 (DOUBLE; T)&amp;gt;,&lt;br /&gt;
  &amp;lt;/sim/aircraft=&amp;quot;bo105&amp;quot; (STRING)&amp;gt; ], airspeed_node : &amp;lt;/velocities/airspe&lt;br /&gt;
  ed-kt=1.021376474393101 (DOUBLE; T)&amp;gt;, aircraft_name : &amp;lt;/sim/aircraft=&amp;quot;bo&lt;br /&gt;
  105&amp;quot; (STRING)&amp;gt; }&lt;br /&gt;
&lt;br /&gt;
====debug.backtrace====&lt;br /&gt;
  debug.backtrace([&amp;lt;comment:string&amp;gt;]}  ... writes backtrace with local variables&lt;br /&gt;
  debug.bt                             ... abbreviation for debug.backtrace&lt;br /&gt;
&lt;br /&gt;
The function debug.backtrace() outputs all local variables of the current function and all parent functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====debug.benchmark====&lt;br /&gt;
debug.benchmark(&amp;lt;label:string&amp;gt;, &amp;lt;func&amp;gt; [, &amp;lt;repeat:int&amp;gt;])&lt;br /&gt;
 ... runs function &amp;lt;repeat&amp;gt; times (default: 1) and prints execution time in seconds,prefixed with &amp;lt;label&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This is extremely useful for benchmarking pieces of code to determin &lt;br /&gt;
====debug.exit====&lt;br /&gt;
  debug.exit()                         ... exits fgfs&lt;br /&gt;
&lt;br /&gt;
== Related content ==&lt;br /&gt;
{{Forum|30|Nasal}}&lt;br /&gt;
* [[:Category:Nasal]]&lt;br /&gt;
&lt;br /&gt;
=== External links ===&lt;br /&gt;
* http://www.plausible.org/nasal&lt;br /&gt;
&lt;br /&gt;
[[Category:Nasal]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Nasal_scripting_language&amp;diff=38415</id>
		<title>Nasal scripting language</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Nasal_scripting_language&amp;diff=38415"/>
		<updated>2011-12-25T05:39:18Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Some success stories */ spelling&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''Please note that a considerable amount of resources has not yet been incorporated here, you can check these out by going to the &amp;quot;[[Talk:Nasal_scripting_language|discussion]]&amp;quot; page, where we are collecting links to webpages and mailing list discussions/postings related to Nasal.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nasal = Not another scripting language!==&lt;br /&gt;
&lt;br /&gt;
 The short summary is that Nasal is a scripting language that is tightly integrated with FlightGear itself, &lt;br /&gt;
 and provides a very easy way to manipulate the property tree, which is the core data structure within the &lt;br /&gt;
 simulator that exposes all the important internal runtime states of FlightGear. &lt;br /&gt;
&lt;br /&gt;
[[FlightGear]] offers a very powerful functional scripting language called [http://plausible.org/nasal/ &amp;quot;Nasal&amp;quot;], which supports reading and writing of internal [[Property Tree Intro|FlightGear properties]], accessing internal data via extension functions, creating GUI dialogs and much more. &lt;br /&gt;
&lt;br /&gt;
Nasal uses some of the concepts of ECMA/JavaScript, Python and Perl and implements a simple but complete way of Object Oriented Programming (OOP), Nasal uses an internal garbage collector so that no manual memory management is required by the programmer. &lt;br /&gt;
&lt;br /&gt;
People familiar with other programming languages, and scripting languages like JavaScript in particular, are usually able to learn Nasal rather quickly. FlightGear provides a rich library of simulation-specific and general-purpose functions that can be accessed by Nasal scripts.&lt;br /&gt;
&lt;br /&gt;
Nasal code can be run by aircraft configuration files, and it can be embedded in various [[XML]] files (dialog files, animation files, bindings for joysticks, keyboard and cockpit controls, and even in [[Howto: Nasal in scenery object XML files|scenery objects]]). Nasal is platform independent and designed to be thread safe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Some success stories ===&lt;br /&gt;
These were taken from the developers mailing list:&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Nasal is *very* well designed, compact, and efficient.  It is used heavily throughout many areas of FlightGear.&amp;quot;&lt;br /&gt;
* &amp;quot;It's interesting though how much nasal you can actually get away with using without making a blip on frame rates.  Nasal is *very* efficient and powerful for being an interpreted script language.&amp;quot;&lt;br /&gt;
* &amp;quot;FlightGear needed a built-in scripting language, and it has one. A compact, clean, elegant and fast one, Nasal extension functions interface perfectly to the property tree, the event manager, the built-in XML parser etc. Nasal is very tightly integrated in fgfs and used all over the place.&amp;quot;&lt;br /&gt;
* &amp;quot;There's no question that scripting languages are good; fgfs has a lot of Nasal code now. In my profiling I have never seen the nasal interpreter as a hot spot&amp;quot;&lt;br /&gt;
* &amp;quot;I'm a simple content contributor with very little background in programming. When I made my first Aircraft (the bf109) I was confronted with the need to deploy slats automatically at a given speed. I din't want to embed C++ code or had such a complex script that the error messages in FG wouldn't help me and I previously only used a bit of python. I looked at some Nasal scripts and within a few hours it worked. I was impressed how easy it is to write even complex Nasal scripts. Later I started developing the walker feature that made it possible to walk around in the scenery, all with nasal. Stuart kindly enhanced the walker and added an animation system to it (see bluebird), again with nasal. Others have made Flight computers with it (see V-22 and Su-37). Nasal is a worthy tool&amp;quot;&lt;br /&gt;
* &amp;quot;I used Nasal to build several rather complex systems, like Fuel System, Stab Augmentation System, Autopilot Logic, Terrain Avoidance Radar, Radar Warning Receiver and much more, and yes, I love Nasal too. Learning Nasal use was easy and fun and I din't found any limitation yet.&amp;quot;&lt;br /&gt;
* There are many vital parts of FlightGear currently coded in nasal.  There are also random bits of nasal code scattered around in joystick configurations, instrument and aircraft models, scenery models...  everywhere.&lt;br /&gt;
* &amp;quot;We have an entire directory full of Nasal 'function' libraries now, and I'm quite happy using them instead of rolling my own duplicate functionality.&amp;quot;&lt;br /&gt;
* Nearly every sophisticated Aircraft uses some kind of Nasal, be it Effects like tyre smoke or important functionalities like Engine and electric management, The Bluebird FDM is completely written in Nasal, vital parts of the V-22 Osprey rely on it, Flyby and Model View wouldn't work anymore, no more interactive objects in the scenery, lots of the MP System would be gone, ... Nasal is THE tool which makes FG development fun and adds nearly unlimited possibilities.  If you need an example, look at the Bluebird animated walker, all done in Nasal.&amp;quot;&lt;br /&gt;
* &amp;quot;there are good reasons to use Nasal - first of all the user base which regularly compiles their own code is small, whereas people do install addon packages - so I get a lot more feedback and test results. Second that one usually can't really crash the whole system from Nasal. Third, it's very easy to quickly try something and very maintenance-friendly. Fourth, you can actually start developing something without knowing how the core code ties together - which I suppose takes a lot of time to learn.  And so on.&amp;quot;&lt;br /&gt;
* &amp;quot;Hard-coding every instrument in C++ instead of nasal means only developers following/building the latest cvs  head code get to use whatever until the next release cycle.&amp;quot;&lt;br /&gt;
* &amp;quot;Hard coding every instrument/flight control in C++ means my WW-II storch (et.al.) is stuck with an autobrake functionality it doesn't have nor need.&amp;quot;&lt;br /&gt;
* &amp;quot;I think it boils down to the fact that we have two approaches that can accomplish the same thing.  The C/C++ approach offers high performance but there is a dependence on when the C/C++ code was added to FlightGear.  The Nasal approach offers fast prototyping, flexibility, and more (but not complete) independence from the C/C++ code.&amp;quot;&lt;br /&gt;
* &amp;quot;A basic problem with C++ functions is it is hard/impossible to override them for a special purpose. Writing in pure nasal allows function name hijacking and other tricks that can't be used on C++ code.&amp;quot;&lt;br /&gt;
* &amp;quot;Given the fact that FG is platform independent, I don't know if the embedded C++ is doing the same on Windows, Linux, PPC and intel Macs. Apart from the fact that if I was able to code c++ I would embed it to FG rather than in an Aircraft specific script&amp;quot;&lt;br /&gt;
* &amp;quot;If we ported Nasal code over to C++ we'd lose the ability to change small things &amp;quot;on the fly&amp;quot; without compiling over and over again. We'd also lose good programmers, who prefer scripting over C++. Aircraft creation would not be customizable etc etc.&amp;quot;&lt;br /&gt;
* &amp;quot;The argument against Nasal is essentially that C++ is faster than Nasal - which, everything else being equal, is certainly correct. But highly specialized Nasal code written for a particular problem outperforms general  purpose C++ code - I've given several examples in the past. If someone were e.g. to add movement to Nasal spawned models by adding a velocity property, I'm not sure it would outperform my Nasal quadtree-sorted adaptive range code which priorizes movement for things actually inside the field of view. Of course, if you'd hard-code that specialized algorithm, it would be faster than the Nasal version - but then you couldn't apply it to other problems any more.&amp;quot;&lt;br /&gt;
* &amp;quot;How many airplane developer will you loose if you remove the Nasal engine from FGFS because they can write Nasal code but not C++ code?&amp;quot;&lt;br /&gt;
* &amp;quot;The algorithm being equal, I don't think there's a question that C++ is faster (I doubt the factor 10 though - that seems to be an extreme case). Everything else being equal, I also don't think there's a question that Nasal code is more accessible. And I would base any decision what to hard-code and what not on that balance.&amp;quot;&lt;br /&gt;
* &amp;quot;Nasal is just much better suited for FlightGear than many alternatives because of it's size, processing speed and because a number of FlightGear core developers have a good idea what's going on.&amp;quot;&lt;br /&gt;
* &amp;quot;In theory we could even use VBScript but Nasal has proven to be valuable for almost 10 years, so no reason to change or add another scripting language. Besides, if you know JavaScript then learning Nasal would take little effort.&amp;quot;&lt;br /&gt;
* &amp;quot;The pool of people with commit rights to the core C++ code is very, very small.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nasal really is an excellent choice for prototyping and implementing new features and even completely new systems in FlightGear. &lt;br /&gt;
&lt;br /&gt;
For example, the [[bombable]] script implements &amp;quot;dog fighting&amp;quot; support on top of FlightGear, without ANY changes to the C++ side of the code, just by using some fairly advanced scripted code (implemented in the built-in Nasal programming language). You can basically imagine it like a &amp;quot;MOD&amp;quot; of FlightGear. In other words, the bombable script creates a completely new &amp;quot;mode&amp;quot; in FlightGear.&lt;br /&gt;
&lt;br /&gt;
No matter if it's scenery, aircraft, AI scenarios or whatever: many things that were originally never planned to be supported by FlightGear core developers, are now implicitly supported because of the loose coupling between highly configurable and flexible systems, such as the property tree and the Nasal scripting language.&lt;br /&gt;
&lt;br /&gt;
So we are really standing on the shoulders of giants here, because we are now -after 10+ years- in the position to create significant new features (and even completely new systems in FlightGear) within the constraints of the FlightGear base package, without even touching the C++ source code at all - simply because FlightGear has become so flexible and extensible.&lt;br /&gt;
&lt;br /&gt;
All of this became possible by some important architectural decisions, such as for example the use of XML and plain text files for pretty much all configuration files in FlightGear (and thus open file formats in general), a publicly accessible tree of state variables that can be easily inspected and modified at runtime (the property tree). Similarly, the decision to embed a scripting language that can be used for scripting the entire simulator was another important decision.&lt;br /&gt;
&lt;br /&gt;
In FlightGear, Nasal is the most accessible method of customizing the whole simulator to a very high degree. Nasal code can be easily edited using a conventional text editor, there are no special tools required: Nasal source code is interpreted, compiled to bytecode and run by the Nasal &amp;quot;virtual machine&amp;quot; using FlightGear itself. &lt;br /&gt;
&lt;br /&gt;
The emerging [[A local weather system|Local weather]] system was entirely prototyped in Nasal space, and is now being increasingly augmented by moving performance-critical functions to C++ space instead.&lt;br /&gt;
&lt;br /&gt;
Using Nasal, it is even possible to create entirely scripted flights and smart &amp;quot;AI bots&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 I have something here that I think is kind of fun.  I've been fiddling with&lt;br /&gt;
 this off and on since last fall and decided it was time to clean it up a bit&lt;br /&gt;
 and quit hording all the fun for myself.  Basically I have taken the F-14b&lt;br /&gt;
 and created a high performance Navy &amp;quot;drone&amp;quot; out of it.  It can auto-launch&lt;br /&gt;
 from a carrier, auto fly a route (if you've input one) and can do circle&lt;br /&gt;
 holds (compensating for wind.)  I've added a simulated&lt;br /&gt;
 gyro stabilized camera that will point at anything you click on and then&lt;br /&gt;
 hold that view steady no matter what the airplane does (similar to what real&lt;br /&gt;
 uav's can do.)  Finally, you can command it to return home and it will find&lt;br /&gt;
 the carrier, setup a reasonable approach and nail the landing perfectly&lt;br /&gt;
 every time (factoring in wind, carrier speed, etc.): http://www.flightgear.org/uas-demo/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As of 03/2009, there were approximately 170.000 lines of reported Nasal source code in the FlightGear base package [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg21333.html], compared to 2006 this is almost a rate of growth of 600% within 3 years [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg01728.html]. This illustrates the sheer adoption rate Nasal is experiencing in FlightGear.&lt;br /&gt;
&lt;br /&gt;
(As of 10/2011, the FlightGear base package contained 326.000 lines of Nasal source code in *.nas files)&lt;br /&gt;
&lt;br /&gt;
Note that this page is mostly about FlightGear-specific APIs/extension functions and usage patterns. &lt;br /&gt;
Thus, you may also want to have a look here:&lt;br /&gt;
&lt;br /&gt;
* [http://plausible.org/nasal/lib.html core language/library documentation] &lt;br /&gt;
* [http://plausible.org/nasal/sample.nas annotated source code examples]&lt;br /&gt;
* [http://plausible.org/nasal/doc.html Nasal design document]&lt;br /&gt;
* [http://www.plausible.org/nasal/flightgear.html a helpful tutorial about using Nasal in FlightGear].&lt;br /&gt;
&lt;br /&gt;
In addition, the [http://gitorious.org/fg/fgdata/trees/master/Nasal Nasal directory] in the FlightGear base package contains a wealth of tested, proven and usually well-commented source code that you may want to check out for additional examples of using the Nasal scripting language in FlightGear [http://gitorious.org/fg/fgdata/trees/master/Nasal].&lt;br /&gt;
&lt;br /&gt;
If you have any Nasal specific questions, you will want to check out the [[Nasal FAQ]], feel free to ask new questions or help answer or refine existing ones. If you would like to learn more about existing Nasal modules in FlightGear, you may want to check out [[Nasal Modules]].&lt;br /&gt;
&lt;br /&gt;
If you are a developer and interested in extending Nasal, you may want to check out [[Howto:Extending Nasal]].&lt;br /&gt;
&lt;br /&gt;
Many short &amp;quot;howto&amp;quot;-style tutorials on Nasal programming can be found in the [[Category:Nasal|Nasal category]].&lt;br /&gt;
&lt;br /&gt;
== Some words on Nasal for fellow C++ programmers ==&lt;br /&gt;
&lt;br /&gt;
Compared to C++, there is really nothing &amp;quot;low quality&amp;quot; about Nasal per se: Nasal is just the &amp;quot;script glue&amp;quot; that connects different parts of the simulator: Many Nasal scripts leverage C++ code - and it is very easy to add new C++ code that can be called from Nasal. &lt;br /&gt;
&lt;br /&gt;
History has shown, that most code in FlightGear will eventually be made more configurable and more accessible, this usually happens in the same steps: 1) replacing static variables with variables stored in the property tree, 2) using listeners to get update notifications for important variables, 3) fully exposing a &amp;quot;control&amp;quot; interface by making it accessible it in the property tree, 4) providing scripting hooks.&lt;br /&gt;
&lt;br /&gt;
Even if you should know C or C++ already, Nasal probably remains the most accessible and the most powerful method for customizing the simulator, simply because it is extremely easy and fast to get started, you don't need an &amp;quot;integrated development environment&amp;quot;, you don't need to install compilers and you don't need to satisfy any 3rd party dependencies; bottom line being: if you can run FlightGear, you can also run Nasal and create new code.&lt;br /&gt;
&lt;br /&gt;
In addition, Nasal code is fairly abstract code, too. Once you start looking at some existing Nasal scripts, you will see that it is also fairly high level code, much more high level than C++ - so Nasal has a much higher density of code, too. Nasal's role in FlightGear really is like JavaScript's role in Firefox, where it is also used for many/most core-related logics (CSS/XUL). &lt;br /&gt;
&lt;br /&gt;
=== Performance ===&lt;br /&gt;
&lt;br /&gt;
Obviously, C++ code will usually be faster than the corresponding Nasal code. But, while performance is not a design goal, Nasal isn't especially slow either. For example, early benchmarks of the garbage collector showed it as faster than perl's reference counter, and its number crunching performance is on par with python. But in all cases, simplicity, transparency and a sane feature set are preferred over speed in Nasal. &lt;br /&gt;
&lt;br /&gt;
Nasal was specifically designed for use as an extension language in an larger project such as FlightGear. The problem with many otherwise excellent languages in this environment is that they are huge. Perl and python are great, but enormous. Even their &amp;quot;core&amp;quot; interpreters and library code are larger than most projects that require an embedded language. They cannot be readily shipped with their host application and need to be installed system-wide. This is a pain and a compatibility hassle. &lt;br /&gt;
&lt;br /&gt;
The real goal with Nasal is to have a language that supports most &amp;quot;normal&amp;quot; programming idioms (objects, functions, arrays, hashes) while avoiding the bloat that comes from &amp;quot;platform&amp;quot; scripting languages like perl, python, ruby and php.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Garbage collection ===&lt;br /&gt;
Nasal garbage collects runtime storage, so the programmer need not worry about manual allocation, or even circular references. The current implementation is a simple mark/sweep collector, which should be acceptable for most applications. Future enhancements will include a &amp;quot;return early&amp;quot; capability for latency-critical applications. The collector can be instructed to return after a certain maximum delay, and be restarted later. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As far as speed goes, the last any benchmarking Nasal was done, it was about as fast as Perl 5 or Python 2.2 at most things.  It's garbage collector was faster, its symbol lookup about the same or slightly faster, and its bytecode interpreter somewhat slower.&lt;br /&gt;
&lt;br /&gt;
=== Thread safety ===&lt;br /&gt;
Unlike almost all other script interpreters (and unlike the FlightGear/Nasal interface itself) , Nasal is thread safe and scalable when called from multiple CPU threads (as opposed to the userspace interpreter threads implemented by Ruby). &lt;br /&gt;
&lt;br /&gt;
No special treatment is required (as for perl, which clones a separate interpreter with separate data for each thread and uses locking around specifically-designated shared data) and the threads can be scheduled simultaneously. There is no global lock on the interpreter, as used by Python or Lua. The only limit on scalability is garbage collection, which must block all interpreter threads before running. &lt;br /&gt;
&lt;br /&gt;
When running threaded code, Nasal provides &amp;quot;minimal threadsafety&amp;quot;, meaning that the interpreter itself can be safely called from multiple CPU threads without risk of corrupting or deadlocking the interpreter internals. Multithreaded operations are therefore &amp;quot;safe&amp;quot;, although they are not guaranteed to be atomic. In particular, poorly synchronized insertions into containers can &amp;quot;drop&amp;quot; objects into oblivion (which is OK from an interpreter stability standpoint, since the GC will clean them up normally). Nasal itself provides no synchronization primitives to address this; thread architecture is a &amp;quot;top-level&amp;quot; design job, and Nasal is intended to be an extension language in a larger project. Choice of synchronization mechanisms is going to be highly application dependent. &lt;br /&gt;
&lt;br /&gt;
=== Exception handling ===&lt;br /&gt;
Like python, nasal supports exception handling as a first-class language feature, with built-in runtime-inspectable stack trace. Rather like perl, however, there is no special &amp;quot;try&amp;quot; syntax for exception handling, nor inheritance-based catching semantics. Instead, you use the call() builtin to invoke a function object and inspect the results to determine what error was thrown (either with the die() builtin or via an internal runtime error) and what the stack trace looked like. Elaborate exception handling isn't really appropriate for embedded scripting languages.&lt;br /&gt;
&lt;br /&gt;
=== High level programming ===&lt;br /&gt;
&lt;br /&gt;
Thus, programmers already familiar with C++ shouldn't just disregard Nasal as a &amp;quot;toy&amp;quot; that doesn't seem suitable for serious development: some of the more complex Nasal scripts can literally make one's head spin around and it would quite obviously take much more C++ or Java code to implement the same features, while sacrificing all the flexibility and power that a scripting language offers. &lt;br /&gt;
&lt;br /&gt;
Some features can certainly be more easily implemented in Nasal space, than in C++ space. Often, the Nasal solution is &amp;quot;on par&amp;quot; with similar solutions in C++.&lt;br /&gt;
&lt;br /&gt;
=== Accessibility ===&lt;br /&gt;
&lt;br /&gt;
For instance, Nasal code cannot only be easily run and contributed by all users, but it can also be easily reused and maintained by other users. This means, that given the number of active C++ developers, compared to the number of base package contributors, your Nasal code is more likely to be actively maintained by fellow users if it is written in Nasal. &lt;br /&gt;
&lt;br /&gt;
In other words, if there are some experimental features you'd like to explore, Nasal is an excellent way to ensure that other FlightGear '''users''' can easily test your new features. This could be witnessed during the development of the local weather system or the bombable addon,too.&lt;br /&gt;
&lt;br /&gt;
This is in stark contrast to features developed solely in C++ space, because these can usually only be tested by people able to build FlightGear from source, especially if your code isn't yet in the main repository, where it would eventually be available in the form of a binary snapshot.&lt;br /&gt;
&lt;br /&gt;
Obviously, none of this is to say that Nasal is the perfect solution for any problem, there are many things for which Nasal isn't necessarily a perfect choice, such as low level code for example (i.e. rendering).&lt;br /&gt;
&lt;br /&gt;
On the other hand, Nasal really is a powerful tool in FlightGear, and if you find that something should, but cannot, be done in Nasal space, it is extremely easy to add support for new features to the Nasal engine using extension functions or property listeners to trigger C/C++ code.&lt;br /&gt;
&lt;br /&gt;
== Creating new Scripts ==&lt;br /&gt;
&lt;br /&gt;
Nasal scripts need to be plain text files, saved with a *.nas extension.&lt;br /&gt;
&lt;br /&gt;
=== Aircraft specific Nasal code ===&lt;br /&gt;
&lt;br /&gt;
Generally, aircraft specific Nasal scripts reside in the corresponding aircraft's folder (or a corresponding /Nasal subfolder) where they are usually included by adding a corresponding &amp;lt;nasal&amp;gt; tag to the aircraft-set.xml file (see [[Writing_simple_scripts_in_%22nasal%22|Writing simple scripts in &amp;quot;nasal&amp;quot;]]). Also see the section on [[Nasal_scripting_language#Namespaces|namespaces]] which contains more specific examples.&lt;br /&gt;
&lt;br /&gt;
=== Instrument specific Nasal code ===&lt;br /&gt;
&lt;br /&gt;
While instrument specific scripts are saved within the instrument's folder (as previously mentioned, Nasal scripts can also be embedded in various other XML files), Nasal scripts driving shared instruments are generally stored in [[$FG ROOT]]/Aircraft/Generic/&lt;br /&gt;
&lt;br /&gt;
=== Nasal code as bindings in XML files ===&lt;br /&gt;
Nasal scripts can also be used as &amp;quot;binding&amp;quot; objects, and can therefore appear anywhere in a configuration file (keyboard, mouse and joystick bindings, etc...) that accepts a &amp;lt;binding&amp;gt; tag. The relevant command type is &amp;quot;nasal&amp;quot;, and you place your Nasal code inside of the &amp;lt;script&amp;gt; tag: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;binding&amp;gt;&lt;br /&gt;
  &amp;lt;command&amp;gt;nasal&amp;lt;/command&amp;gt;&lt;br /&gt;
  &amp;lt;script&amp;gt;&lt;br /&gt;
   print(&amp;quot;Binding Invoked!&amp;quot;);&lt;br /&gt;
  &amp;lt;/script&amp;gt;&lt;br /&gt;
 &amp;lt;/binding&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code above invokes the print() function. This is a simple extension function that simply prints out its arguments, in order, to the FlightGear console as a single-line log entry. It is useful for debugging, but little else. &lt;br /&gt;
&lt;br /&gt;
=== System-wide Nasal code ===&lt;br /&gt;
&lt;br /&gt;
Nasal scripts that are not specific to certain aircraft, instruments or other uses, generally reside in the system-wide [[$FG ROOT]]/Nasal directory.&lt;br /&gt;
&lt;br /&gt;
Nasal scripts that are placed inside [[$FG ROOT]]/Nasal (with a *.nas extension) are automatically loaded and run during FlightGear startup. &lt;br /&gt;
&lt;br /&gt;
=== Nasal sub modules ===&lt;br /&gt;
&lt;br /&gt;
As of 06/2011, FlightGear also supports so called Nasal &amp;quot;sub modules&amp;quot; which may reside in their own sub folder under $FG_ROOT/Nasal/ and which provide support for on-demand loading at runtime by toggling properties.&lt;br /&gt;
&lt;br /&gt;
Some advantages are:&lt;br /&gt;
&lt;br /&gt;
* Nasal files can be grouped neatly instead of all scripts being mixed up in a single fgdata/Nasal directory. Grouping makes a lot of sense for modules consisting of several scripts - local weather is the best example.&lt;br /&gt;
* Guaranteed loading sequence. Submodules are loaded _after_ the main fgdata/Nasal scripts, so they can rely on all fgdata/Nasal content to be already present. No more need for awkward listener callbacks, just to make sure that basic &amp;quot;props&amp;quot; or &amp;quot;gui&amp;quot; modules are available.&lt;br /&gt;
* Finally, users have the option to disable loading modules. Unfortunately, just loading scripts (code/data) into memory already causes certain _run-time_ performance effects - even if the Nasal code was never executed (so even when all listeners/timers were disabled).&lt;br /&gt;
&lt;br /&gt;
Please note that there is  a difference between the _individual_ Nasal files in fgdata/Nasal and files belonging to a common Nasal _module in general (no matter whether loaded at run-time or loaded at start-up using a &amp;quot;&amp;lt;nasal&amp;gt;&amp;quot; tag).&lt;br /&gt;
&lt;br /&gt;
The individual Nasal files in fgdata/Nasal have an own namespace _each_. The namespace get's the name of the Nasal file itself. So if you have a &amp;quot;gui.nas&amp;quot; in the directory, then you can reference a symbol &amp;quot;foo&amp;quot; using &amp;quot;gui.foo&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Nasal modules also have a single namespace. But all files belonging to the module share this _single_ namespace. The name of their namespace is made from its directory (for the run-time loadable modules), or from the specific tag given below the &amp;lt;nasal&amp;gt; XML element, which are often used for a/c specific modules (e.g. &amp;lt;nasal&amp;gt;&amp;lt;ufo&amp;gt;...&amp;lt;/ufo&amp;gt;&amp;lt;/nasal&amp;gt; creates the ufo Nasal namespace in ufo-set.xml).&lt;br /&gt;
&lt;br /&gt;
'''So each Nasal file in a new Nasal &amp;quot;module&amp;quot; folder now shares the same namespace.'''&lt;br /&gt;
&lt;br /&gt;
For more information on Nasal sub modules, please see [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg32657.html] and [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg33458.html].&lt;br /&gt;
&lt;br /&gt;
=== User specific Nasal scripts ===&lt;br /&gt;
&lt;br /&gt;
It's also possible to put Nasal files into $FG_HOME/Nasal/, that is: ~/.fgfs/Nasal/ on Unix, and %APPDATA%\flightgear.org\Nasal\ on MS Windows. This has the following advantages:&lt;br /&gt;
&lt;br /&gt;
* one doesn't have to mix local extensions with standard files&lt;br /&gt;
* one is less likely to lose such local additions when upgrading&lt;br /&gt;
* one doesn't need write permission to $FG_ROOT/Nasal/ or&lt;br /&gt;
* one doesn't have to become &amp;quot;root&amp;quot; to edit such files&lt;br /&gt;
&lt;br /&gt;
The files are guaranteed to be read after all the files in $FG_ROOT/Nasal/, so one can safely use elements of files like props.nas (props.Node), or globals.nas (setlistener() without leading underscore).&lt;br /&gt;
&lt;br /&gt;
The files are guaranteed to be read in alphabetic order. So, if there are two files where one depends on the other, just name them appropriately.&lt;br /&gt;
&lt;br /&gt;
The contents of each file are added to a namespace derived from the filename. So, all functions and variables of a file ~/.fgfs/nasal/local.nas will be added to nasal namespace &amp;quot;local&amp;quot;, and a function test() is globally accessible as local.test().&lt;br /&gt;
&lt;br /&gt;
It's possible to extend a standard module like &amp;quot;math&amp;quot; with definitions in ~/.fgfs/Nasal/math.nas, though this should, of course, not be exploited by code that is to be submitted to cvs.&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
&lt;br /&gt;
A simple hello world example in Nasal would be:&lt;br /&gt;
&lt;br /&gt;
 # hello.nas&lt;br /&gt;
 print('Hello World!');&lt;br /&gt;
&lt;br /&gt;
This will show the &amp;quot;Hello World&amp;quot; string during startup in the console window. The hash sign (#) just introduces comments (i.e. will be ignored by the interpreter).&lt;br /&gt;
&lt;br /&gt;
Note: Script-specific symbols such as global variables (or functions) will be put into a scope (namespace) based on the script's name, scripts embedded via aircraft-set.xml files can separately specify a corresponding module name (see [[Howto: Make an aircraft]] for details).&lt;br /&gt;
&lt;br /&gt;
Strings in Nasal can also use double quotes which support escaping:&lt;br /&gt;
 # hello.nas&lt;br /&gt;
 print(&amp;quot;Hello\nWorld!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Double quotes support typical escape sequences:&lt;br /&gt;
&lt;br /&gt;
* \n 	Newline&lt;br /&gt;
* \t	Horizontal Tab&lt;br /&gt;
* \v	Vertical Tab&lt;br /&gt;
* \b	Backspace&lt;br /&gt;
* \r	Carriage Return&lt;br /&gt;
* \f	Form feed&lt;br /&gt;
* \a	Audible Alert (bell)&lt;br /&gt;
* \\	Backslash&lt;br /&gt;
* \?	Question mark&lt;br /&gt;
* \'	Single quote&lt;br /&gt;
* \&amp;quot;	Double quote&lt;br /&gt;
&lt;br /&gt;
For example, to print a new line, use:&lt;br /&gt;
&lt;br /&gt;
 print (&amp;quot;\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
To print a quoted string, use:&lt;br /&gt;
&lt;br /&gt;
 print (&amp;quot;\&amp;quot;quoted string\&amp;quot;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
and so on.&lt;br /&gt;
&lt;br /&gt;
Single quotes treat everything as literal except for embedded single quotes (including embedded whitespace like newlines).&lt;br /&gt;
&lt;br /&gt;
Nasal strings are always arrays of bytes (never characters: see the utf8 library if you want character-based equivalents of substr() et. al.). They can be indexed just like in C (although note that there is no nul termination -- get the length with size()):&lt;br /&gt;
&lt;br /&gt;
== Editing code files ==&lt;br /&gt;
&lt;br /&gt;
Note that there is currently no way to tell FlightGear to reload Nasal scripts from the global Nasal directory at runtime, so in order to see changes take effect, you will have to exit and restart FlightGear for the time being. Note that there are some workarounds available, see: [[Nasal_scripting_language#Loading.2Freloading_Nasal_code_without_re-starting_Flightgear|reloading Nasal code without re-starting FlightGear]].&lt;br /&gt;
&lt;br /&gt;
Also, note that as of 05/2009, Nasal in FlightGear does not yet support any form of dependency resolution. In other words, there's no &amp;quot;import&amp;quot;, &amp;quot;require&amp;quot; or &amp;quot;include&amp;quot; directive - this is also why most code in FlightGear is wrapped inside a _setlistener() call instead, which in turn waits for a FlightGear signal before executing the code (see below for details).&lt;br /&gt;
&lt;br /&gt;
== Variables ==&lt;br /&gt;
Nasal scripts should make use of the var keyword when declaring variables. The &amp;quot;var&amp;quot; keyword makes a variable guaranteed to be local. Nasal, natively provides support for scalars (numbers, strings), lists (arrays, vectors) and hashes (objects or dictionaries), more complex data structures (such as trees) can be built using vectors or hashes.&lt;br /&gt;
&lt;br /&gt;
 var w=100;     # w is a local numerical variable&lt;br /&gt;
 var x=&amp;quot;hello&amp;quot;; # x is a local string variable&lt;br /&gt;
 var y=[];      # y is a local vector (array)&lt;br /&gt;
 var z={};      # z is a local hash (dictionary or table) - also used for OOP&lt;br /&gt;
&lt;br /&gt;
Nasal supports a &amp;quot;nil&amp;quot; value for use as a null pointer equivalent:&lt;br /&gt;
&lt;br /&gt;
 var foo=nil; &lt;br /&gt;
&lt;br /&gt;
Also, note that Nasal symbols are case-sensitive, these are all different variables:&lt;br /&gt;
&lt;br /&gt;
 var show = func(what) {print(what,&amp;quot;\n&amp;quot;);}&lt;br /&gt;
 var abc=1; # these are all different symbols&lt;br /&gt;
 var ABC=2; # different from abc &lt;br /&gt;
 var aBc=3; # different from abc and ABC&lt;br /&gt;
 &lt;br /&gt;
 show(abc);&lt;br /&gt;
 show(ABC);&lt;br /&gt;
 show(aBc);&lt;br /&gt;
&lt;br /&gt;
Please note that functions assigned to variables are no exception. If you write code without using &amp;quot;var&amp;quot; on variables, then you risk (often hard to debug) breakage at a later time because you may be overwriting symbols in another namespace. &lt;br /&gt;
&lt;br /&gt;
So functions bound to variables should use the &amp;quot;var&amp;quot; keyword as well:&lt;br /&gt;
&lt;br /&gt;
 var hello = func { &lt;br /&gt;
   print(&amp;quot;hello\n&amp;quot;); &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
But there's another reason why &amp;quot;var&amp;quot; should be used consequently, even if a variable is safe enough from later side effects, because it has a relatively specific or unique name: The &amp;quot;var&amp;quot; keyword makes&lt;br /&gt;
reading code for others (and for the author after some time) easier, as it makes clear: &amp;quot;this variable starts its life *HERE*&amp;quot;. No need to search around to see whether assigning a value to it means something to other code outside or not. Also, with an editor offering proper syntax highlighting reading such code is actually easier, despite the &amp;quot;noise&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The problem with nasal code that does not make use of the var keyword is, that it can break other code, and with it the whole system, but no Nasal error message will point you there, as it's syntactically and semantically correct code. Just doing things that it wasn't supposed to do.&lt;br /&gt;
For a more in-depth discussion, please see [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg13557.html].&lt;br /&gt;
&lt;br /&gt;
Also, Nasal scripts that are loaded from $FG_ROOT/Nasal are automatically placed inside a namespace that is based on the script's name.&lt;br /&gt;
&lt;br /&gt;
For example, referring to our earlier &amp;quot;Hello World&amp;quot; example, global variables defined in the hello.nas script would be accessible by using &amp;quot;hello&amp;quot; as prefix from other modules:&lt;br /&gt;
&lt;br /&gt;
 # hello.nas&lt;br /&gt;
 var greeting=&amp;quot;Hello World&amp;quot;; # define a greeting symbol inside the hello namespace&lt;br /&gt;
&lt;br /&gt;
If you were now to read out the value from the greeting variable from another Nasal module, you would have to use the hello prefix:&lt;br /&gt;
&lt;br /&gt;
 # greetme.nas&lt;br /&gt;
 print(hello.greeting); # the hello prefix is referring to the hello namespace (or module).&lt;br /&gt;
&lt;br /&gt;
==Namespaces==&lt;br /&gt;
The Nasal Console built into FlightGear is quite handy when it comes to debugging code. However, here the namespaces need to be considered. In addition, Nasal sub modules (see above) have some special rules, too - basically, all Nasal files part of a &amp;quot;sub module&amp;quot; share a single name space based on the folder's name rather than the name of the individual Nasal files.&lt;br /&gt;
&lt;br /&gt;
For cases of Nasal code specific for an aircraft (like instruments, for example), the corresponding scripts could be loaded through the aircraft's &amp;lt;tt&amp;gt;-set.xml&amp;lt;/tt&amp;gt; file by putting it into the &amp;lt;tt&amp;gt;&amp;lt;nasal&amp;gt;...&amp;lt;/nasal&amp;gt;&amp;lt;tt&amp;gt; section&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;nasal&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;moduleA&amp;gt;&lt;br /&gt;
      &amp;lt;file&amp;gt;path/to/file1.nas&amp;lt;/file&amp;gt;&lt;br /&gt;
      &amp;lt;file&amp;gt;path/to/file2.nas&amp;lt;/file&amp;gt;		&lt;br /&gt;
    &amp;lt;/moduleA&amp;gt;&lt;br /&gt;
    &amp;lt;moduleB&amp;gt;&lt;br /&gt;
      &amp;lt;file&amp;gt;path/to/file3.nas&amp;lt;/file&amp;gt;	&lt;br /&gt;
    &amp;lt;/moduleB&amp;gt;&lt;br /&gt;
  &amp;lt;/nasal&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, variables in files &amp;lt;tt&amp;gt;path/to/file1.nas&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;path/to/file2.nas&amp;lt;/tt&amp;gt; can be used in the Nasal console as&lt;br /&gt;
&lt;br /&gt;
  moduleA.varName;&lt;br /&gt;
&lt;br /&gt;
Variables in &amp;lt;tt&amp;gt;path/to/file3.nas&amp;lt;/tt&amp;gt; can be accessed as&lt;br /&gt;
&lt;br /&gt;
  moduleB.varName;&lt;br /&gt;
&lt;br /&gt;
Please note that Nasal sub modules (i.e. files loaded and run from their own Nasal sub directory), are subject to some special rules, as all Nasal source files are automatically loaded into the same namespace, which is by default based on the sub module's folder name.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''More information can be found by clicking [http://wiki.flightgear.org/Namespaces_and_Methods here].'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Variables - Advanced Uses ==&lt;br /&gt;
&lt;br /&gt;
Nasal, also supports Multi-assignment expressions. You can assign more than one variable (or lvalue) at a time by putting them in a parenthesized list:&lt;br /&gt;
&lt;br /&gt;
   (var a, var b) = (1, 2);&lt;br /&gt;
   var (a, b) = (1, 2);               # Shorthand for (var a, var b)&lt;br /&gt;
   (var a, v[0], obj.field) = (1,2,3) # Any assignable lvalue works&lt;br /&gt;
   var color = [1, 1, 0.5];&lt;br /&gt;
   var (r, g, b) = color;  # works with runtime vectors too&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Vectors (lists or arrays) can be created from others using an ordered list of indexes and ranges. &lt;br /&gt;
This is usually called &amp;quot;vector slicing&amp;quot;.&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
   var v1 = [&amp;quot;a&amp;quot;,&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;,&amp;quot;d&amp;quot;,&amp;quot;e&amp;quot;]&lt;br /&gt;
   # &lt;br /&gt;
   var v2 = v1[3,2];   # == [&amp;quot;d&amp;quot;,&amp;quot;c&amp;quot;];&lt;br /&gt;
   var v3 = v1[1:3];   # i.e. range from 1 to 3: [&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;,&amp;quot;d&amp;quot;];&lt;br /&gt;
   var v4 = v1[1:];    # no value means &amp;quot;to the end&amp;quot;: [&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;,&amp;quot;d&amp;quot;,&amp;quot;e&amp;quot;]&lt;br /&gt;
   var i = 2;&lt;br /&gt;
   var v5 = v1[i];     # runtime expressions are fine: [&amp;quot;c&amp;quot;]&lt;br /&gt;
   var v6 = v1[-2,-1]; # negative indexes are relative to end: [&amp;quot;d&amp;quot;,&amp;quot;e&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
The range values can be computed at runtime (e.g. i=1; v5=v1[i:]). Negative indices work the same way they do with the vector functions (-1 is the last element, -2 is 2nd to last, etc...).&lt;br /&gt;
&lt;br /&gt;
== Storage: property tree vs. Nasal ==&lt;br /&gt;
With FlightGear's built-in property tree and Nasal's support for it, there are two obvious, and two somewhat competing, ways for storing scalar data: native Nasal variables and FlightGear properties, both of which can be easily accessed and managed from Nasal.&lt;br /&gt;
&lt;br /&gt;
The advantage to native Nasal-space data is that it's fast and simple.  If the only thing that will care about the value is your script, they are good choices.&lt;br /&gt;
&lt;br /&gt;
The property tree is an inter-subsystem communication thing.  This is what you want if you want to share data with the C++ world (for example, YASim &amp;lt;control-output&amp;gt; tags write to properties -- they don't understand Nasal), or read in via configuration files.&lt;br /&gt;
&lt;br /&gt;
Also, native Nasal data structures are usually far faster than their equivalent in property tree space.  This is because there are several layers of indirection in retrieving a property tree value. &lt;br /&gt;
&lt;br /&gt;
In general, this means that you shouldn't make overly excessive use of the property tree for storing state that isn't otherwise relevant to FlightGear or any of its subsystems. Doing that would in fact have adverse effects on the performance of your code. In general, you should favor Nasal variables and data structures and should only make use of properties to interface with the rest of FlightGear, or to easily provide debugging information at run time.&lt;br /&gt;
&lt;br /&gt;
As of FG 2.4.0, retrieving a value from the property tree via getprop is about 50% slower than accessing a native Nasal variable, and accessing the value via node.getValue() is 10-20% slower yet. This is an insignificant amount of time if you are retrieving and storing a few individual values from the property tree, but adds up fast if you are storing or retrieving hashes or large amounts of data.  (You can easily benchmark times on your own code using systime() or debug.benchmark.)&lt;br /&gt;
&lt;br /&gt;
In addition, it is worth noting that the Nasal/FlightGear APIs cannot currently be considered to be thread safe, this mean that -at least for now- the explicit use of pure Nasal space variables is the only way to exploit possible parallelism in your code by making use of threads.&lt;br /&gt;
&lt;br /&gt;
== Functions ==&lt;br /&gt;
&lt;br /&gt;
=== What is a function ? ===&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;function&amp;quot; is a piece of code that can be easily used repeatedly (without repeating the same code over and over again), this is achieved by associating a symbolic name with the piece of code, such as &amp;quot;print&amp;quot;, &amp;quot;show&amp;quot; or &amp;quot;get&amp;quot; for example. Whenever this symbolic name is then used in the program, the program will &amp;quot;jump&amp;quot; to the definition of the function and start running it, once the called function has completed it will automatically return to the instruction following the call.&lt;br /&gt;
&lt;br /&gt;
By using so called &amp;quot;function arguments&amp;quot; (see below) it is possible to parametrize a function (using variables) so that it may use data that is specific to each invocation.&lt;br /&gt;
&lt;br /&gt;
As previously shown, Nasal functions are implemented using the func keyword, The following snippet of code defines a new function named &amp;quot;log_message&amp;quot; with an empty function body (the curly braces).&lt;br /&gt;
&lt;br /&gt;
 var log_message = func {}&lt;br /&gt;
&lt;br /&gt;
=== Function bodies ===&lt;br /&gt;
&lt;br /&gt;
To add a function body, you need to add code in between these curly braces.&lt;br /&gt;
&lt;br /&gt;
=== Anonymous function arguments ===&lt;br /&gt;
&lt;br /&gt;
In Nasal, arguments are by default passed in the &amp;quot;arg&amp;quot; array, not unlike perl. To understand how this works, you should probably first read up on Nasal vectors.&lt;br /&gt;
&lt;br /&gt;
 var log_message = func {&lt;br /&gt;
    print(arg[0]);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Note that this is equivalent to:&lt;br /&gt;
&lt;br /&gt;
 var log_message = func() {&lt;br /&gt;
    print(arg[0]);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In other words, the argument list &amp;quot;()&amp;quot; can be omitted if it is empty.&lt;br /&gt;
However, if you are new to Nasal or programming in general, it is probably a good idea to ALWAYS use parentheses, i.e. also for functions with empty argument lists - that makes it easy to get used to the syntax.&lt;br /&gt;
&lt;br /&gt;
Note that this is just an assignment of an (anonymous) function argument to the local &amp;quot;log_message&amp;quot; variable. There is no function declaration syntax in Nasal.&lt;br /&gt;
&lt;br /&gt;
Also, Nasal being a functional programming language, all passed arguments will be local to the corresponding scope. If you want to modify state in a function, you'll preferably return new state to the caller.&lt;br /&gt;
&lt;br /&gt;
===Named function arguments===&lt;br /&gt;
You can also pass named arguments to a function, thus saving the typing and performance costs of extracting them from the arg array:&lt;br /&gt;
&lt;br /&gt;
 var log_message = func(msg) {&lt;br /&gt;
    print(msg);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The list of function arguments is called a function's &amp;quot;signature&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Default values for function arguments ===&lt;br /&gt;
&lt;br /&gt;
Function arguments can have default values, as in C++. Note that the default value must be a scalar (number, string, function, nil) and not a mutable composite object (list, hash).&lt;br /&gt;
&lt;br /&gt;
 var log_message = func(msg=&amp;quot;error&amp;quot;) {&lt;br /&gt;
    print(msg);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If some arguments have default values and some do not, those with default values must come first in the argument list:&lt;br /&gt;
&lt;br /&gt;
 #Incorrect:&lt;br /&gt;
 var log_message = func(msg=&amp;quot;error&amp;quot;, line, object=&amp;quot;ground&amp;quot;) { #some code }&lt;br /&gt;
&lt;br /&gt;
 #Correct:&lt;br /&gt;
 var log_message = func(msg=&amp;quot;error&amp;quot;, object=&amp;quot;ground&amp;quot;, line) { #some code }&lt;br /&gt;
&lt;br /&gt;
Any extra arguments after the named list are placed in the &amp;quot;arg&amp;quot; vector as above. You can rename this to something other than &amp;quot;arg&amp;quot; by specifying a final argument name with an ellipsis:&lt;br /&gt;
&lt;br /&gt;
 listify = func(elements...) { return elements; }&lt;br /&gt;
 listify(1, 2, 3, 4); # returns a list: [1, 2, 3, 4]&lt;br /&gt;
&lt;br /&gt;
=== Returning from functions ===&lt;br /&gt;
&lt;br /&gt;
In Nasal, functions return implicitly the values of the last expression (i.e. &amp;quot;nil&amp;quot; in empty function bodies), you can also add an explicit &amp;quot;return&amp;quot; statement, for example to leave a function early. In addition, it is possible to return values, too.&lt;br /&gt;
&lt;br /&gt;
So, semantically, the previous snippet of code is equivalent to these:&lt;br /&gt;
&lt;br /&gt;
 var log_message = func {return;}&lt;br /&gt;
&lt;br /&gt;
 var log_message = func {nil;}&lt;br /&gt;
&lt;br /&gt;
 var log_message = func {}; &lt;br /&gt;
&lt;br /&gt;
 var log_message = func return;&lt;br /&gt;
&lt;br /&gt;
 var log_message = func nil;&lt;br /&gt;
&lt;br /&gt;
===Named arguments in function calls===&lt;br /&gt;
Nasal supports named function arguments in function calls, too.&lt;br /&gt;
&lt;br /&gt;
As an alternative to the comma-separated list of ''positional'' function arguments, you can specify a hash literal in place of ordered function arguments, and it will become the local variable namespace for the called function, with variables named according to the hash indexes and with values according to the hash values.  This makes functions with many arguments more readable. &lt;br /&gt;
&lt;br /&gt;
And it also makes it possible to call function's without having to take care of the right order of passing arguments.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
 #if we have functions defined:&lt;br /&gt;
 var log_message = func (msg=&amp;quot;&amp;quot;) { #some code to log variable msg }&lt;br /&gt;
 var lookat =  func (heading=0, pitch=0, roll=0, x=nil, y=nil, z=nil, time=hil, fov=20) { #some code using those variables }&lt;br /&gt;
&lt;br /&gt;
 #we can use them them the usual way with comma separated list of arguments:&lt;br /&gt;
 log_message(&amp;quot;Hello World!&amp;quot;);&lt;br /&gt;
 lookat (180, 20, 0, XO, YO, ZO, now, 55);&lt;br /&gt;
&lt;br /&gt;
 #or we can use the hash literal arguments instead:&lt;br /&gt;
 log_message(msg:&amp;quot;Hello World!&amp;quot;);&lt;br /&gt;
 lookat(heading:180, pitch:20, roll:0, x:X0, y:Y0, z:Z0,time:now, fov:55);&lt;br /&gt;
&lt;br /&gt;
Both methods for calling the functions above are equivalent, but note the the second method is more readable, less prone to error, and self-documenting in the code for the function call.&lt;br /&gt;
&lt;br /&gt;
As another example, consider:&lt;br /&gt;
&lt;br /&gt;
 var setPosition = func (latitude_deg, longitude_deg, altitude_ft) {&lt;br /&gt;
  # do something here &lt;br /&gt;
 }&lt;br /&gt;
 # the actual function call:&lt;br /&gt;
 setPosition( latitude_deg:34.00, longitude_deg:7.00, alt_ft:10000);&lt;br /&gt;
&lt;br /&gt;
In other words, such function calls become much more self-explanatory because everybody can see immediately what a value is doing.&lt;br /&gt;
This is a good practice, as you may eventually have to take a longer break, away from your code - and then even you yourself will come to appreciate such small things that make code more intuitive to work with.&lt;br /&gt;
&lt;br /&gt;
Declared arguments are checked and defaulted as would be expected: it's an error if you fail to pass a value for an undefaulted argument, missing default arguments get assigned as usual, and any rest parameter (e.g. &amp;quot;func(a,b=2,rest...){}&amp;quot;) will be assigned with an empty vector.&lt;br /&gt;
&lt;br /&gt;
===Nested functions, implicit return ===&lt;br /&gt;
Also, Nasal functions can be easily nested, for example:&lt;br /&gt;
&lt;br /&gt;
  var calculate = func(param1,param2,operator) {&lt;br /&gt;
   var add = func(p1,p2) {p1+p2;}&lt;br /&gt;
   var sub = func(p1,p2) {p1-p2;}&lt;br /&gt;
   var mul = func(p1,p2) {p1*p2;}&lt;br /&gt;
   var div = func(p1,p2) {p1/p2;}&lt;br /&gt;
   if (operator==&amp;quot;+&amp;quot;) return add(param1,param2);&lt;br /&gt;
   if (operator==&amp;quot;-&amp;quot;) return sub(param1,param2);&lt;br /&gt;
   if (operator==&amp;quot;*&amp;quot;) return mul(param1,param2);&lt;br /&gt;
   if (operator==&amp;quot;/&amp;quot;) return div(param1,param2);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Note that the add,sub,mul and div functions in this example do not make use of an explicit return statement, instead the result of each expression is implicitly returned to the caller.&lt;br /&gt;
&lt;br /&gt;
Nasal functions that just consist of such simple expressions can also be further simplified to read:&lt;br /&gt;
&lt;br /&gt;
  var add = func(val1,val2) val1+val2;&lt;br /&gt;
&lt;br /&gt;
=== Function overloading ===&lt;br /&gt;
&lt;br /&gt;
Note that Nasal functions can generally not be [[http://en.wikipedia.org/wiki/Function_overloading overloaded]], and that operator overloading in particular is also not supported.&lt;br /&gt;
&lt;br /&gt;
However, the effects of '''function overloading''' can obviously be implemented individually by each function, simply by processing the number and type of passed arguments at the start of the function body. The FlightGear code base contains a number of examples for this, i.e. it is for example possible to pass properties in the form of plain strings to a callback or in the form of a Nasal wrapper like props.Node.&lt;br /&gt;
&lt;br /&gt;
So this can be accomplished by first checking the argument count and then the types of arguments passed to the function.&lt;br /&gt;
&lt;br /&gt;
To provide an example, here's a simple function to multiply two numbers, no matter if they are provided as scalars, as a vector or as x/y members of a hash:&lt;br /&gt;
&lt;br /&gt;
 var multiply2 = func (params) {&lt;br /&gt;
  if (typeof(params)==&amp;quot;scalar&amp;quot;) return params*arg[0];&lt;br /&gt;
  if (typeof(params)==&amp;quot;vector&amp;quot;) return params[0]*params[1];&lt;br /&gt;
  if (typeof(params)==&amp;quot;hash&amp;quot;)   return params.x*params.y;&lt;br /&gt;
  die(&amp;quot;cannot do what you want me to do&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
So, now you have a very simple form of an &amp;quot;overloaded&amp;quot; function that supports different argument types and numbers:&lt;br /&gt;
&lt;br /&gt;
 multiply2(  2,6); # multiply two scalars&lt;br /&gt;
 multiply2( [5,7] ); # multiply two scalars stored in a vector&lt;br /&gt;
 multiply2( {x:8, y:9} ); # multiply two scalars stored in a hash&lt;br /&gt;
&lt;br /&gt;
You could obviously extend this easily to support an arbitrary number of arguments by just using a for loop here.&lt;br /&gt;
&lt;br /&gt;
As you can see, the basic idea is pretty simple and also scalable, you could easily extend this to and also return different types of values, such as vectors or hashes. This could for example be used to create wrappers in Nasal space for doing 3D maths, with vectors and matrices, so that a matrix multiplication could return a new matrix, too.&lt;br /&gt;
&lt;br /&gt;
===Functional programming, higher order functions, generators;===&lt;br /&gt;
As previously mentioned, arguments to a Nasal function can also be functions themselves (Nasal being a functional programming language), this means that Nasal functions are higher order functions so that you can easily pass and return functions to and from Nasal functions. This can for example be used to dynamically create new functions (such functions are commonly called 'generators'):&lt;br /&gt;
&lt;br /&gt;
  # a function that returns a new custom function&lt;br /&gt;
  var i18n_hello = func(hello) {&lt;br /&gt;
   return func(name) { # returns an anonymous/unnamed function&lt;br /&gt;
     print(hello,name);&lt;br /&gt;
   }&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
  # create three new functions&lt;br /&gt;
  var english_hello = i18n_hello(&amp;quot;Good Day &amp;quot;);&lt;br /&gt;
  var spanish_hello = i18n_hello(&amp;quot;Buenos Dias &amp;quot;);&lt;br /&gt;
  var italian_hello = i18n_hello(&amp;quot;Buon giorno &amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
  # actually call these functions&lt;br /&gt;
  english_hello(&amp;quot;FlightGear&amp;quot;);&lt;br /&gt;
  spanish_hello(&amp;quot;FlightGear&amp;quot;);&lt;br /&gt;
  italian_hello(&amp;quot;FlightGear&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
=== Using helper functions ===&lt;br /&gt;
&lt;br /&gt;
It is possible to simplify complex function calls by introducing small helper functions, for example consider:&lt;br /&gt;
&lt;br /&gt;
 var l = thermalLift.new(ev.lat, ev.lon, ev.radius, ev.height, ev.cn, ev.sh, ev.max_lift, ev.f_lift_radius);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, you could just as well create a small helper function named&amp;quot;thermalLift.new_from_ev(ev)&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
  thermalLift.new_from_ev = func (ev) {&lt;br /&gt;
   thermalLift.new(ev.lat, ev.lon, ev.radius, ev.height, ev.cn, ev.sh, ev.max_lift, ev.f_lift_radius);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 var l=thermalLift.new_from_ev(ev);&lt;br /&gt;
&lt;br /&gt;
Note that the expression to invoke your code would then also become less complicated and much more comprehensible.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you have expressions of nested method calls, such as:&lt;br /&gt;
&lt;br /&gt;
    t.getNode(&amp;quot;latitude-deg&amp;quot;).setValue(f.getNode(&amp;quot;latitude-deg&amp;quot;).getValue());&lt;br /&gt;
    t.getNode(&amp;quot;longitude-deg&amp;quot;).setValue(f.getNode(&amp;quot;longitude-deg&amp;quot;).getValue());&lt;br /&gt;
&lt;br /&gt;
You could just as easily introduce a small helper function to wrap the code, that would be less typing for you, less code to read (and understand) for others and generally it would help localize functionality (and possible errors):&lt;br /&gt;
&lt;br /&gt;
    var copyNode = func(t,f,path) t.getNode(path).setValue(f.getNode(path).getValue());&lt;br /&gt;
&lt;br /&gt;
So you would simply take the complex expression and generalize it by adding variables that you pass in from a function object, then you could simply call your new function like this:&lt;br /&gt;
&lt;br /&gt;
    copyNode(t,f,&amp;quot;latitude-deg&amp;quot;);&lt;br /&gt;
    copyNode(t,f,&amp;quot;longitude-deg&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
    foreach(var p; [&amp;quot;latitude-deg&amp;quot;, &amp;quot;longitude-deg&amp;quot;,&amp;quot;generated-flag&amp;quot;])&lt;br /&gt;
      copyNode(t,f,p);&lt;br /&gt;
&lt;br /&gt;
or as a complete function accepting a vector of properties:&lt;br /&gt;
&lt;br /&gt;
    var copyNode = func(target,source,properties) { &lt;br /&gt;
     if (typeof(properties)!=&amp;quot;vector&amp;quot;) properties=[properties];&lt;br /&gt;
     if (typeof(target)!=&amp;quot;hash&amp;quot;) target=props.globals.getNode(target);&lt;br /&gt;
     if (typeof(source)!=&amp;quot;hash&amp;quot;) target=props.globals.getNode(source)&lt;br /&gt;
     foreach(var path; properties)&lt;br /&gt;
      target.getNode(path).setValue( source.getNode(path).getValue() );&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    copyNode(&amp;quot;/temp/test&amp;quot;, &amp;quot;/position&amp;quot;, [&amp;quot;latitude-deg&amp;quot;, &amp;quot;longitude-deg&amp;quot;, &amp;quot;altitude-ft&amp;quot;]);&lt;br /&gt;
&lt;br /&gt;
Whenever you have very similar lines of code that seem fairly repetitive, it is a good idea to consider introducing small helper functions. You can use plenty of small helper functions and then just &amp;quot;chain&amp;quot; them together, rather than using complex nested expressions that make your head spin.&lt;br /&gt;
&lt;br /&gt;
== Conditionals ==&lt;br /&gt;
&lt;br /&gt;
Nasal has no &amp;quot;statements&amp;quot;, which means that any expression can appear in any context. This means that you can use an if/else clause to do what the ?: does in C. &lt;br /&gt;
The last semicolon in a code block is optional, to make this prettier&lt;br /&gt;
&lt;br /&gt;
 abs = func(n) { if(n&amp;lt;0) { -n } else { n } }&lt;br /&gt;
&lt;br /&gt;
But for those who don't like typing, the ternary operator works like you expect:&lt;br /&gt;
&lt;br /&gt;
 abs = func(n) { n &amp;lt; 0 ? -n : n }&lt;br /&gt;
&lt;br /&gt;
In addition, Nasal supports braceless blocks, like they're known from C/C++ and other languages:&lt;br /&gt;
&lt;br /&gt;
 var foo=1;&lt;br /&gt;
 if (foo)&lt;br /&gt;
   print(&amp;quot;1\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
   print(&amp;quot;0\n&amp;quot;);&lt;br /&gt;
 print(&amp;quot;this is printed regardless\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Instead of a switch statement one can use&lt;br /&gt;
&lt;br /&gt;
  if (1==2) {&lt;br /&gt;
    print(&amp;quot;wrong&amp;quot;);&lt;br /&gt;
  } else if (1==3) { # NOTE the space between else and if&lt;br /&gt;
    print(&amp;quot;wronger&amp;quot;);&lt;br /&gt;
  } else {&lt;br /&gt;
    print(&amp;quot;don't know&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
which produces the expected output of &amp;lt;code&amp;gt;don't know&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;nil&amp;lt;/tt&amp;gt; logic is actually quite logical, let's just restate the obvious:&lt;br /&gt;
&lt;br /&gt;
  if (nil) {&lt;br /&gt;
    print(&amp;quot;This should never be printed&amp;quot;);&lt;br /&gt;
  } else {&lt;br /&gt;
    print(&amp;quot;This will be printed, because nil is always false&amp;quot;);		&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nasal's binary boolean operators are &amp;quot;and&amp;quot; and &amp;quot;or&amp;quot;, unlike C. unary not is still &amp;quot;!&amp;quot; however. &lt;br /&gt;
They short-circuit like you expect&lt;br /&gt;
&lt;br /&gt;
 var toggle = 0;&lt;br /&gt;
 var a = nil;&lt;br /&gt;
 if(a and a.field == 42) {&lt;br /&gt;
    toggle = !toggle; # doesn't crash when a is nil&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
You can easily reduce the complexity of huge conditional (IF) statements, such as this one:&lt;br /&gt;
&lt;br /&gt;
    if (a==1) function_a();&lt;br /&gt;
    else&lt;br /&gt;
    if (a==2) function_b();&lt;br /&gt;
    else&lt;br /&gt;
    if (a==3) function_c();&lt;br /&gt;
    else&lt;br /&gt;
    if (a==4) function_d();&lt;br /&gt;
    else&lt;br /&gt;
    if (a==5) function_e();&lt;br /&gt;
&lt;br /&gt;
.. just by using the variable as a key (index) into a hash, so that you can directly call the corresponding function:&lt;br /&gt;
&lt;br /&gt;
    var mapping = {1:function_a, 2:function_b, 3:function_c, 4:function_d,5:function_e};&lt;br /&gt;
    mapping[a] ();&lt;br /&gt;
&lt;br /&gt;
This initializes first a hash map of values and maps a function &amp;quot;pointer&amp;quot; to each value, so that accessing mapping[x] will return the function pointer for the key &amp;quot;x&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Next, you can actually call the function by appending a list of function arguments (empty parentheses for no args) to the hash lookup.&lt;br /&gt;
&lt;br /&gt;
Using this technique, you can reduce the complexity of huge conditional blocks. For example, consider:&lt;br /&gt;
&lt;br /&gt;
    # weather_tile_management.nas&lt;br /&gt;
    460         if (code == &amp;quot;altocumulus_sky&amp;quot;){weather_tiles.set_altocumulus_tile();}&lt;br /&gt;
    461         else if (code == &amp;quot;broken_layers&amp;quot;) {weather_tiles.set_broken_layers_tile();}&lt;br /&gt;
    462         else if (code == &amp;quot;stratus&amp;quot;) {weather_tiles.set_overcast_stratus_tile();}&lt;br /&gt;
    463         else if (code == &amp;quot;cumulus_sky&amp;quot;) {weather_tiles.set_fair_weather_tile();}&lt;br /&gt;
    464         else if (code == &amp;quot;gliders_sky&amp;quot;) {weather_tiles.set_gliders_sky_tile();}&lt;br /&gt;
    465         else if (code == &amp;quot;blue_thermals&amp;quot;) {weather_tiles.set_blue_thermals_tile();}&lt;br /&gt;
    466         else if (code == &amp;quot;summer_rain&amp;quot;) {weather_tiles.set_summer_rain_tile();}&lt;br /&gt;
    467         else if (code == &amp;quot;high_pressure_core&amp;quot;) {weather_tiles.set_high_pressure_core_tile();}&lt;br /&gt;
    468         else if (code == &amp;quot;high_pressure&amp;quot;) {weather_tiles.set_high_pressure_tile();}&lt;br /&gt;
    469         else if (code == &amp;quot;high_pressure_border&amp;quot;) {weather_tiles.set_high_pressure_border_tile();}&lt;br /&gt;
    470         else if (code == &amp;quot;low_pressure_border&amp;quot;) {weather_tiles.set_low_pressure_border_tile();}&lt;br /&gt;
    471         else if (code == &amp;quot;low_pressure&amp;quot;) {weather_tiles.set_low_pressure_tile();}&lt;br /&gt;
    472         else if (code == &amp;quot;low_pressure_core&amp;quot;) {weather_tiles.set_low_pressure_core_tile();}&lt;br /&gt;
    473         else if (code == &amp;quot;cold_sector&amp;quot;) {weather_tiles.set_cold_sector_tile();}&lt;br /&gt;
    474         else if (code == &amp;quot;warm_sector&amp;quot;) {weather_tiles.set_warm_sector_tile();}&lt;br /&gt;
    475         else if (code == &amp;quot;tropical_weather&amp;quot;) {weather_tiles.set_tropical_weather_tile();}&lt;br /&gt;
    476         else if (code == &amp;quot;test&amp;quot;) {weather_tiles.set_4_8_stratus_tile();}&lt;br /&gt;
    477         else ...&lt;br /&gt;
&lt;br /&gt;
While this is not a very complex or huge block of code, it is an excellent example for very good naming conventions used already, because the consistency of naming variables and functions can pay off easily here, with just some very small changes, you can already reduce the whole thing to a hash lookup like this:&lt;br /&gt;
&lt;br /&gt;
  weather_tiles[&amp;quot;set_&amp;quot;~code~&amp;quot;_tile&amp;quot;]();  # naming convention&lt;br /&gt;
&lt;br /&gt;
This would dynamically concatenate a key consisting of &amp;quot;set_&amp;quot; + code + &amp;quot;_title&amp;quot; into the hash named weather_tiles, and then call the function that is returned from the hash lookup.&lt;br /&gt;
&lt;br /&gt;
So for this to work you only need to enforce consistency when naming your functions (i.e. this would of course CURRENTLY fail when the variable code contains &amp;quot;test&amp;quot; because there is no such hash member (it's &amp;quot;4_8_stratus&amp;quot; instead).&lt;br /&gt;
&lt;br /&gt;
The same applies to cumulus sky (fair weather), stratus/overcast stratus.&lt;br /&gt;
&lt;br /&gt;
But these are very simple changes to do (just renaming these functions to match the existing conventions). When you do that, you can easily replace such huge IF statements and replace them with a single hash lookup and function call:&lt;br /&gt;
&lt;br /&gt;
 hash[key] (arguments...);&lt;br /&gt;
&lt;br /&gt;
For example, consider:&lt;br /&gt;
&lt;br /&gt;
 var makeFuncString = func(c) return tolower(&amp;quot;set_&amp;quot;~c~&amp;quot;_tile&amp;quot;);&lt;br /&gt;
 var isFunc = func(f) typeof(f)=='func';&lt;br /&gt;
 var hasMethod = func(h,m) contains(h,m) and isFunc;&lt;br /&gt;
 var callIfAvailable = func(hash, method, unavailable=func{} ) {&lt;br /&gt;
  var c=hasMethod(hash,makeFuncString(m) ) or unavailable();&lt;br /&gt;
  hash[makeFuncString(m)] ();&lt;br /&gt;
 }&lt;br /&gt;
 callIfAvailable( weather_tiles,code, func {die(&amp;quot;key not found in hash or not a func&amp;quot;);} );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Initializing data structures ==&lt;br /&gt;
&lt;br /&gt;
There are some more possibilities to increase the density of your code, such as by removing redundant code or by generalizing and refactoring existing code so that it can be reused in different places (i.e. avoiding duplicate code): &lt;br /&gt;
&lt;br /&gt;
For example see weather_tile_management.nas #1000 (create_neighbours function):&lt;br /&gt;
&lt;br /&gt;
    1008 x = -40000.0; y = 40000.0;&lt;br /&gt;
    1009 setprop(lw~&amp;quot;tiles/tile[0]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1010 setprop(lw~&amp;quot;tiles/tile[0]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1011 setprop(lw~&amp;quot;tiles/tile[0]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1012 setprop(lw~&amp;quot;tiles/tile[0]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1013 setprop(lw~&amp;quot;tiles/tile[0]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1014 setprop(lw~&amp;quot;tiles/tile[0]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1015 setprop(lw~&amp;quot;tiles/tile[0]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1016&lt;br /&gt;
    1017 x = 0.0; y = 40000.0;&lt;br /&gt;
    1018 setprop(lw~&amp;quot;tiles/tile[1]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1019 setprop(lw~&amp;quot;tiles/tile[1]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1020 setprop(lw~&amp;quot;tiles/tile[1]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1021 setprop(lw~&amp;quot;tiles/tile[1]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1022 setprop(lw~&amp;quot;tiles/tile[1]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1023 setprop(lw~&amp;quot;tiles/tile[1]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1024 setprop(lw~&amp;quot;tiles/tile[1]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1025&lt;br /&gt;
    1026 x = 40000.0; y = 40000.0;&lt;br /&gt;
    1027 setprop(lw~&amp;quot;tiles/tile[2]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1028 setprop(lw~&amp;quot;tiles/tile[2]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1029 setprop(lw~&amp;quot;tiles/tile[2]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1030 setprop(lw~&amp;quot;tiles/tile[2]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1031 setprop(lw~&amp;quot;tiles/tile[2]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1032 setprop(lw~&amp;quot;tiles/tile[2]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1033 setprop(lw~&amp;quot;tiles/tile[2]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1034&lt;br /&gt;
    1035 x = -40000.0; y = 0.0;&lt;br /&gt;
    1036 setprop(lw~&amp;quot;tiles/tile[3]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1037 setprop(lw~&amp;quot;tiles/tile[3]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1038 setprop(lw~&amp;quot;tiles/tile[3]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1039 setprop(lw~&amp;quot;tiles/tile[3]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1040 setprop(lw~&amp;quot;tiles/tile[3]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1041 setprop(lw~&amp;quot;tiles/tile[3]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1042 setprop(lw~&amp;quot;tiles/tile[3]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1043&lt;br /&gt;
    1044 # this is the current tile&lt;br /&gt;
    1045 x = 0.0; y = 0.0;&lt;br /&gt;
    1046 setprop(lw~&amp;quot;tiles/tile[4]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1047 setprop(lw~&amp;quot;tiles/tile[4]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1048 setprop(lw~&amp;quot;tiles/tile[4]/generated-flag&amp;quot;,1);&lt;br /&gt;
    1049 setprop(lw~&amp;quot;tiles/tile[4]/tile-index&amp;quot;,1);&lt;br /&gt;
    1050 setprop(lw~&amp;quot;tiles/tile[4]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1051 setprop(lw~&amp;quot;tiles/tile[4]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1052 setprop(lw~&amp;quot;tiles/tile[4]/orientation-deg&amp;quot;,getprop(lw~&amp;quot;tmp/tile-orientation-deg&amp;quot;));&lt;br /&gt;
    1053&lt;br /&gt;
    1054&lt;br /&gt;
    1055 x = 40000.0; y = 0.0;&lt;br /&gt;
    1056 setprop(lw~&amp;quot;tiles/tile[5]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1057 setprop(lw~&amp;quot;tiles/tile[5]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1058 setprop(lw~&amp;quot;tiles/tile[5]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1059 setprop(lw~&amp;quot;tiles/tile[5]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1060 setprop(lw~&amp;quot;tiles/tile[5]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1061 setprop(lw~&amp;quot;tiles/tile[5]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1062 setprop(lw~&amp;quot;tiles/tile[5]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1063&lt;br /&gt;
    1064 x = -40000.0; y = -40000.0;&lt;br /&gt;
    1065 setprop(lw~&amp;quot;tiles/tile[6]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1066 setprop(lw~&amp;quot;tiles/tile[6]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1067 setprop(lw~&amp;quot;tiles/tile[6]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1068 setprop(lw~&amp;quot;tiles/tile[6]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1069 setprop(lw~&amp;quot;tiles/tile[6]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1070 setprop(lw~&amp;quot;tiles/tile[6]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1071 setprop(lw~&amp;quot;tiles/tile[6]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1072&lt;br /&gt;
    1073 x = 0.0; y = -40000.0;&lt;br /&gt;
    1074 setprop(lw~&amp;quot;tiles/tile[7]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1075 setprop(lw~&amp;quot;tiles/tile[7]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1076 setprop(lw~&amp;quot;tiles/tile[7]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1077 setprop(lw~&amp;quot;tiles/tile[7]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1078 setprop(lw~&amp;quot;tiles/tile[7]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1079 setprop(lw~&amp;quot;tiles/tile[7]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1080 setprop(lw~&amp;quot;tiles/tile[7]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1081&lt;br /&gt;
    1082 x = 40000.0; y = -40000.0;&lt;br /&gt;
    1083 setprop(lw~&amp;quot;tiles/tile[8]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1084 setprop(lw~&amp;quot;tiles/tile[8]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1085 setprop(lw~&amp;quot;tiles/tile[8]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1086 setprop(lw~&amp;quot;tiles/tile[8]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1087 setprop(lw~&amp;quot;tiles/tile[8]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1088 setprop(lw~&amp;quot;tiles/tile[8]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1089 setprop(lw~&amp;quot;tiles/tile[8]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1090 }&lt;br /&gt;
&lt;br /&gt;
At first glance, this seems like a fairly repetitive and redundant block of code, so it could probably be simplified easily:&lt;br /&gt;
&lt;br /&gt;
    var create_neighbours = func (blat, blon, alpha)        {&lt;br /&gt;
    var phi = alpha * math.pi/180.0;&lt;br /&gt;
    calc_geo(blat);&lt;br /&gt;
    var index=0;&lt;br /&gt;
    var pos = [  [-40000.0,40000.0], [0.0, 40.000], [40000.0, 40000.0], [-40000, 0],  [0,0], [40000,0], [-40000,-40000], [0,-40000], [40000,-40000] ];&lt;br /&gt;
    foreach (var p;pos) {&lt;br /&gt;
    x=p[0]; y=p[1];&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/generated-flag&amp;quot;,0);&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/tile-index&amp;quot;,-1);&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    index=index+1;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
&lt;br /&gt;
Nasal has several ways to implement an iteration.&lt;br /&gt;
&lt;br /&gt;
===for, while, foreach, and forindex loops===&lt;br /&gt;
Nasal's looping constructs are mostly C-like:&lt;br /&gt;
&lt;br /&gt;
 for(var i=0; i &amp;lt; 3; i = i+1) {&lt;br /&gt;
  # loop body&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
 while (condition) {&lt;br /&gt;
 # loop body&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The differences are that there is no do{}while(); construct, and there is a foreach, which takes a local variable name as its first argument and a vector as its second:&lt;br /&gt;
&lt;br /&gt;
  foreach(elem; list1) { doSomething(elem); }  # NOTE: the delimiter is a SEMICOLON ;&lt;br /&gt;
&lt;br /&gt;
The hash/vector index expression is an lvalue that can be assigned as well as inspected:&lt;br /&gt;
&lt;br /&gt;
  foreach(light; lights) { lightNodes[light] = propertyPath; }&lt;br /&gt;
&lt;br /&gt;
To walk through all elements of a hash, for a foreach loop on the keys of they hash.  Then you call pull up the values of the hash using the key.  Example:&lt;br /&gt;
&lt;br /&gt;
 myhash= {first: 1000, second: 250, third: 25.2 };&lt;br /&gt;
 foreach (var i; keys (myhash)) {&lt;br /&gt;
   #multiply each value by 2:&lt;br /&gt;
   myhash[i] *= 2; &lt;br /&gt;
   #print the key and new value:&lt;br /&gt;
   print (i, &amp;quot;: &amp;quot;, myhash[i]);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
There is also a &amp;quot;forindex&amp;quot;, which is like foreach except that it assigns the index of each element, instead of the value, to the loop variable.&lt;br /&gt;
&lt;br /&gt;
 forindex(i; list1) { doSomething(list1[i]); }&lt;br /&gt;
&lt;br /&gt;
Also, braceless blocks work for loops equally well:&lt;br /&gt;
&lt;br /&gt;
 var c=0;&lt;br /&gt;
 while( c&amp;lt;5 )&lt;br /&gt;
  print( c+=1 );&lt;br /&gt;
 print(&amp;quot;end of loop\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
===settimer loops===&lt;br /&gt;
Loops using &amp;lt;tt&amp;gt;while&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;foreach&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;forindex&amp;lt;/tt&amp;gt; block all of FlightGear's subsystems that run in the main thread, and can, thus, only be used for instantaneous operations that don't take too long. &lt;br /&gt;
&lt;br /&gt;
For operations that should continue over a longer period, one needs a non-blocking solution. This is done by letting functions call themselves after a timed delay: &lt;br /&gt;
&lt;br /&gt;
 var loop = func {&lt;br /&gt;
     print(&amp;quot;this line appears once every two seconds&amp;quot;);&lt;br /&gt;
     settimer(loop, 2);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 loop();        # start loop&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;settimer&amp;lt;/tt&amp;gt; function expects a ''function object'' (&amp;lt;tt&amp;gt;loop&amp;lt;/tt&amp;gt;), not a function call (&amp;lt;tt&amp;gt;loop()&amp;lt;/tt&amp;gt;) (though it is possible to make a function call return a function object--an advanced functional programming technique that you won't need to worry about if you're just getting started with Nasal). &lt;br /&gt;
&lt;br /&gt;
The fewer code FlightGear has to execute, the better, so it is desirable to run loops only when they are needed. But how does one stop a loop? A once triggered timer function can't be revoked. But one can let the loop function check an outside variable and refuse calling itself, which makes the loop chain die off:&lt;br /&gt;
&lt;br /&gt;
 var running = 1;&lt;br /&gt;
 var loop = func {&lt;br /&gt;
     if (running) {&lt;br /&gt;
         print(&amp;quot;this line appears once every two seconds&amp;quot;);&lt;br /&gt;
         settimer(loop, 2);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 loop();        # start loop ...&lt;br /&gt;
 ...&lt;br /&gt;
 running = 0;   # ... and let it die&lt;br /&gt;
&lt;br /&gt;
Unfortunately, this method is rather unreliable. What if the loop is &amp;quot;stopped&amp;quot; and a new instance immediately started again? Then the ''running'' variable would be ''1'' again, and a pending old loop call, which should really finish this chain, would happily continue. And the new loop chain would start, too, so that we would end up with two loop chains.&lt;br /&gt;
&lt;br /&gt;
This can be solved by providing each loop chain with a ''loop identifier'' and letting the function end itself if the id doesn't match the global loop-id. Self-called loop functions need to inherit the chain id. So, every time the global loop id is increased, all loop chains die, and a new one can immediately be started.&lt;br /&gt;
&lt;br /&gt;
 var loopid = 0;&lt;br /&gt;
 var loop = func(id) {&lt;br /&gt;
     id == loopid or return;           # stop here if the id doesn't match the global loop-id&lt;br /&gt;
     ...&lt;br /&gt;
     settimer(func { loop(id) }, 2);   # call self with own loop id&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 loop(loopid);       # start loop&lt;br /&gt;
 ...&lt;br /&gt;
 loopid += 1;        # this kills off all pending loops, as none can have this new identifier yet&lt;br /&gt;
 ...&lt;br /&gt;
 loop(loopid);       # start new chain; this can also be abbreviated to:  loop(loopid += 1);&lt;br /&gt;
&lt;br /&gt;
[[Nasal_scripting_language#settimer.28.29|More information about the settimer function is below]]&lt;br /&gt;
&lt;br /&gt;
== OOP - Object Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
In Nasal, objects (&amp;quot;classes&amp;quot;) are regular hashes. Self-reference and inheritance are implemented through special variables &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt;. To get a better understanding of the concept, let's start with the very basics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Hashes ===&lt;br /&gt;
&lt;br /&gt;
Hashes, also known as &amp;quot;dictionaries&amp;quot; in Python or &amp;quot;maps&amp;quot; in C++/STL are data structures that hold key/value pairs in a way that allows quick access to a value via its key.&lt;br /&gt;
&lt;br /&gt;
 var airport = {&lt;br /&gt;
     &amp;quot;LOXZ&amp;quot;: &amp;quot;Zeltweg&amp;quot;,&lt;br /&gt;
     &amp;quot;LOWI&amp;quot;: &amp;quot;Innsbruck&amp;quot;,&lt;br /&gt;
     &amp;quot;LOXL&amp;quot;: &amp;quot;Linz Hoersching&amp;quot;,     # the last comma is optional&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 print(airport[&amp;quot;LOXZ&amp;quot;]);            # prints &amp;quot;Zeltweg&amp;quot;&lt;br /&gt;
 airport[&amp;quot;LOXA&amp;quot;] = &amp;quot;Aigen&amp;quot;;         # adds LOXA to the hash&lt;br /&gt;
&lt;br /&gt;
The built-in function keys() returns a vector with the keys of the hash.  The function values() returns a vector with the values of the hash. For example:&lt;br /&gt;
&lt;br /&gt;
  debug.dump (keys(airport)); #prints ['LOXZ', 'LOWI', 'LOXL']&lt;br /&gt;
  debug.dump (values (airport)); #prints ['Zeltweg', 'Innsbruck', 'Linz Hoersching'] &lt;br /&gt;
&lt;br /&gt;
The quotes around keys can be left away in a hash definition if the key is a valid variable name or a number. This works just as well:&lt;br /&gt;
&lt;br /&gt;
 var airport = {&lt;br /&gt;
     LOXZ: &amp;quot;Zeltweg&amp;quot;,&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
There's also an alternative way to access hash members if the keys are valid variable names: &amp;lt;tt&amp;gt;airport.LOXI&amp;lt;/tt&amp;gt; can be used instead of &amp;lt;tt&amp;gt;airport[&amp;quot;LOXI&amp;quot;]&amp;lt;/tt&amp;gt;. There is a difference, though, which is described in the next section.&lt;br /&gt;
&lt;br /&gt;
Note that assigning a hash (or a vector) to another variable does never ''copy'' the contents. It only creates another reference to the same data structure. So manipulating the hash via its new name does in fact change the one, original hash.&lt;br /&gt;
&lt;br /&gt;
 var a = airport;&lt;br /&gt;
 a.LOXL = &amp;quot;Linz&amp;quot;;           # same as airport.LOXL!&lt;br /&gt;
 print(airport.LOXL);       # prints now &amp;quot;Linz&amp;quot;, not &amp;quot;Linz Hoersching&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(True copies of vectors can be made by assigning a full slice: &amp;lt;tt&amp;gt;var copy = vec[:]&amp;lt;/tt&amp;gt;. There's no such method for hashes.)&lt;br /&gt;
&lt;br /&gt;
=== Self-reference: &amp;quot;&amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt;&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
Values stored in a hash can be of any type, even of type ''function''. Member functions (&amp;quot;methods&amp;quot;) can reference their own enclosing hash via reserved keyword &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt;. This is comparable to the &amp;lt;tt&amp;gt;this&amp;lt;/tt&amp;gt; keyword in C++ classes, or the &amp;lt;tt&amp;gt;self&amp;lt;/tt&amp;gt; keyword in Python.&lt;br /&gt;
&lt;br /&gt;
 var value = &amp;quot;test&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
 var data = {&lt;br /&gt;
     value: 23,                         # scalar member variable&lt;br /&gt;
     write1: func { print(value); },    # function member&lt;br /&gt;
     write2: func { print(me.value); }, # function member&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 data.write1();     # prints &amp;quot;test&amp;quot;&lt;br /&gt;
 data.write2();     # prints 23&lt;br /&gt;
&lt;br /&gt;
The above example is already a simple form of an object. It has its own variable namespace (''data''), its own methods, and it can be passed around by-reference as one unit. Such classes are sometimes called ''singleton classes'', as they are unique, with no independent class instances. They mostly serve as a way to keep data and methods nicely encapsulated within a Nasal module. Often they contain a method for initializing, which is usually called &amp;lt;tt&amp;gt;init&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Inheritance: &amp;quot;&amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt;&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
What we learned about &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; in the last section is only half the truth. &amp;quot;me&amp;quot; doesn't only reference an object's own hash, but also one or more parent hashes. &amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt; is another reserved keyword. It denotes a vector referencing other object hashes, which are &amp;quot;inherited&amp;quot; that way.&lt;br /&gt;
&lt;br /&gt;
Please note that Nasal's currently supported form of encapsulation does not provide support for any form of data/information hiding (restricting access), i.e. all hash fields (but also all hash methods) are always publicly accessible (so there's nothing like the &amp;quot;private&amp;quot; or &amp;quot;protected&amp;quot; keywords in C++: in this sense, Nasal's inheritance mechanism can be thought of like C++ structs which are also public by default).&lt;br /&gt;
&lt;br /&gt;
The major difference being, that all members (functions and fields) are also always '''mutable''', which means that functions can modify the behavior of other functions quite easily, this also applies to the parents vector, too.&lt;br /&gt;
&lt;br /&gt;
 var parent_object = {&lt;br /&gt;
     value: 123,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var object = {&lt;br /&gt;
     parents: [parent_object],&lt;br /&gt;
     write: func { print(me.value) },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 object.write();    # prints 123&lt;br /&gt;
&lt;br /&gt;
Even though &amp;lt;tt&amp;gt;object&amp;lt;/tt&amp;gt; itself doesn't contain a member &amp;lt;tt&amp;gt;value&amp;lt;/tt&amp;gt;, it finds and uses the one of its parent object. &amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt; is a vector that can contain several parent objects. These are then searched in the order from left to right, until a matching member variable or method is found. Each of the parents can itself have parents, which are all recursively searched.&lt;br /&gt;
&lt;br /&gt;
In the section about hashes it was said that hash members can be accessed in two alternative ways, and that's also true for methods. &amp;lt;tt&amp;gt;object.write()&amp;lt;/tt&amp;gt; could also be called as &amp;lt;tt&amp;gt;object[&amp;quot;write&amp;quot;]()&amp;lt;/tt&amp;gt;. But only in the first form will members also be searched in parent hashes if not found in the base hash, whereas the second form creates an error if it's not a direct member.&lt;br /&gt;
&lt;br /&gt;
=== Creating class instances ===&lt;br /&gt;
&lt;br /&gt;
With &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt; we can implement a class object and create independent instances from that:&lt;br /&gt;
&lt;br /&gt;
 var Class = {&lt;br /&gt;
     write:     func { print(me.value); },&lt;br /&gt;
     increment: func { me.value += 1; },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var instance1 = { parents: [Class], value: 123 };&lt;br /&gt;
 var instance2 = { parents: [Class], value: 456 };&lt;br /&gt;
 &lt;br /&gt;
 instance1.write();    # prints 123&lt;br /&gt;
 instance2.write();    # prints 456&lt;br /&gt;
&lt;br /&gt;
As you can see, the two class instances are separate, independent objects, which share another object as parent -- they &amp;quot;inherit&amp;quot; from object &amp;lt;tt&amp;gt;Class&amp;lt;/tt&amp;gt;. One can now easily change members of any of these three objects. The following will redefine the parent's &amp;lt;tt&amp;gt;write&amp;lt;/tt&amp;gt; method, and all instances will automatically use this new version:&lt;br /&gt;
&lt;br /&gt;
 Class.write = func { print(&amp;quot;VALUE = &amp;quot; ~ me.value) }&lt;br /&gt;
&lt;br /&gt;
But one can also add a method to just one instance:&lt;br /&gt;
&lt;br /&gt;
 instance1.write = func { print(&amp;quot;VALUE = &amp;quot; ~ me.value) }&lt;br /&gt;
&lt;br /&gt;
Because &amp;lt;tt&amp;gt;instance1&amp;lt;/tt&amp;gt; does now have its own &amp;lt;tt&amp;gt;write&amp;lt;/tt&amp;gt; method, the parents won't be searched for one, so &amp;lt;tt&amp;gt;Class.write&amp;lt;/tt&amp;gt; is now overridden by &amp;lt;tt&amp;gt;instance1&amp;lt;/tt&amp;gt;'s own method. Nothing changed for &amp;lt;tt&amp;gt;instance2&amp;lt;/tt&amp;gt; -- it will still only find and use &amp;lt;tt&amp;gt;Class.write&amp;lt;/tt&amp;gt; via its parent.&lt;br /&gt;
&lt;br /&gt;
Note, the we couldn't create a class instance by simple assignment, because, as we learned above, this wouldn't create a separate copy of the Class object. All &amp;quot;instances&amp;quot; would reference the same hash!&lt;br /&gt;
&lt;br /&gt;
 var bad_instance1 = Class;   # bad&lt;br /&gt;
 var bad_instance2 = Class;   # bad&lt;br /&gt;
 &lt;br /&gt;
 bad_instance1.value = 123;   # sets Class.value to 123&lt;br /&gt;
 bad_instance2.value = 456;   # sets Class.value to 456&lt;br /&gt;
 &lt;br /&gt;
 bad_instance1.write();       # prints 456, not 123&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
Defining each class instance by explicitly creating a hash with parents is clumsy. It is nicer to have a function that does that for us. Then we can also use function arguments to initialize members of this instance.&lt;br /&gt;
&lt;br /&gt;
 var new_class = func(val) {&lt;br /&gt;
     return { parents: [Class], value: val };&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 var instance1 = new_class(123);&lt;br /&gt;
 var instance2 = new_class(456);&lt;br /&gt;
 &lt;br /&gt;
 instance1.write();   # prints 123&lt;br /&gt;
 instance2.write();   # prints 456&lt;br /&gt;
&lt;br /&gt;
Because the class generating function &amp;lt;tt&amp;gt;new_class()&amp;lt;/tt&amp;gt; really belongs to class &amp;lt;tt&amp;gt;Class&amp;lt;/tt&amp;gt;, it would be nicer to put it into the class hash as well. In this case we call it a class &amp;quot;constructor&amp;quot;, and as a convention, give it the name ''new''. It could have any name, though, and there could be more than one constructor.&lt;br /&gt;
&lt;br /&gt;
 var Class = {&lt;br /&gt;
     new: func(val) {&lt;br /&gt;
         return { parents: [Class], value: val };&lt;br /&gt;
     },&lt;br /&gt;
     write: func {&lt;br /&gt;
         print(&amp;quot;VALUE=&amp;quot; ~ me.value);&lt;br /&gt;
     },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var instance1 = Class.new(123);&lt;br /&gt;
 var instance2 = Class.new(456);&lt;br /&gt;
&lt;br /&gt;
As you can see, &amp;lt;tt&amp;gt;new()&amp;lt;/tt&amp;gt; doesn't return a copy of &amp;lt;tt&amp;gt;Class&amp;lt;/tt&amp;gt;, but rather a small hash that contains only a list of parents and one individual member &amp;lt;tt&amp;gt;value&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Classes aren't always as simple as in our example. Usually they contain several members, of which some may have yet to be calculated in the constructor. In that case it's easier to create a local object hash first, and to let the constructor finally return it. Such local hashes are often named &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt; (as a short reference to &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt;), or &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 var Class = {&lt;br /&gt;
     new: func(val) {&lt;br /&gt;
         var m = { parents: [Class] };&lt;br /&gt;
         m.value = val;&lt;br /&gt;
         return m;&lt;br /&gt;
     },&lt;br /&gt;
     write: func {&lt;br /&gt;
         print(&amp;quot;VALUE=&amp;quot; ~ me.value);&lt;br /&gt;
     },&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
This last example is the most frequently used form of class definitions in FlightGear-Nasal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Destructor ===&lt;br /&gt;
&lt;br /&gt;
There's no such thing in Nasal. In other languages destructors are automatically called when the class gets destroyed, so that memory and other resources that were allocated by the constructor can be freed. In Nasal that's all done by the Garbage Collector (GC), anyway. In the FlightGear context, however, there ''are'' resources that should get freed. Listeners should get removed, self-calling functions (&amp;quot;loops&amp;quot;) stopped. For that it's recommended to create a destructor function and to call that manually. Such functions are often called &amp;lt;tt&amp;gt;del&amp;lt;/tt&amp;gt;, similar to Python and to pair nicely with the three-letter constructor name &amp;lt;tt&amp;gt;new&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Memory management ===&lt;br /&gt;
&lt;br /&gt;
Finally, as you know now, Nasal, being a dynamic programming language, doesn't require or support any manual memory management, so unlike C++, you don't need to call operators like &amp;quot;new&amp;quot; or &amp;quot;delete&amp;quot; to allocate or free your memory.&lt;br /&gt;
&lt;br /&gt;
However, if you do know that you don't need a certain variable anymore, you can certainly give a hint to the built-in garbage collector to free it, by assigning a &amp;quot;nil&amp;quot; value to it. &lt;br /&gt;
&lt;br /&gt;
This can certainly pay off when using more complex data structures such as nested vectors or hashes, because it will tell the built-in garbage collector to remove all references to the corresponding symbols, so that they can be freed.&lt;br /&gt;
&lt;br /&gt;
It is also possible to make use of Nasal's delete() function to remove a symbol from a namespace (hash).&lt;br /&gt;
&lt;br /&gt;
So, if you are concerned about your script's memory requirements, using a combination of setting symbols to nil, or deleting them as appropriate, would allow you to create helper functions for freeing data structures easily.&lt;br /&gt;
&lt;br /&gt;
In addition, it is probably worth noting that this is also the only way to sanely reset an active Nasal namespace or even the whole interpreter. You need to do this in order to reload or re-initialize your code without restarting the whole FlightGear session [[Nasal_scripting_language#Managing_timers_and_listeners]].&lt;br /&gt;
&lt;br /&gt;
Obviously, you should first of all ensure that there is no more code running, this includes any registered listeners or timers, but also any others loops or recursive functions.&lt;br /&gt;
&lt;br /&gt;
Thus, if you'd like to reload a Nasal source file at run time, you should disable all running code, and then reset the corresponding namespace, too. This is to ensure that you get a clean and consistent namespace.&lt;br /&gt;
&lt;br /&gt;
Nasal provides a number of core library functions to manipulate namespaces, such as:&lt;br /&gt;
&lt;br /&gt;
* caller() - to get a strack trace of active functions currently on the Nasal stack&lt;br /&gt;
* compile() - to compile new Nasal code &amp;quot;on the fly&amp;quot;, i.e. dynamically from a string&lt;br /&gt;
* closure() - to query the lexical namespace of active functions&lt;br /&gt;
* bind() - to create new function objects&lt;br /&gt;
&lt;br /&gt;
More information is available here: http://www.plausible.org/nasal/lib.html&lt;br /&gt;
&lt;br /&gt;
If, on the other hand, you are using these data structures in some repeated fashion, it might make sense to keep the data structure itself around and simply re-use it next time (overwriting data as required), instead of always allocating/creating a new one, this is called &amp;quot;caching&amp;quot; and can pay off from a performance perspective.&lt;br /&gt;
&lt;br /&gt;
=== Multiple inheritance ===&lt;br /&gt;
&lt;br /&gt;
A class can inherit from one or more other classes. It can then access all methods and class members of all parent classes, but also override them and add additional members.&lt;br /&gt;
&lt;br /&gt;
 var A = {                                            # simple class A&lt;br /&gt;
     new: func {&lt;br /&gt;
         return { parents: [A] };&lt;br /&gt;
     },&lt;br /&gt;
     alpha: func print(&amp;quot;\tALPHA&amp;quot;),&lt;br /&gt;
     test:  func print(&amp;quot;\tthis is A.test&amp;quot;),&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var B = {                                            # simple class B&lt;br /&gt;
     new: func(v) {                                   # ... whose constructor takes an argument&lt;br /&gt;
         return { parents: [B], value: v };&lt;br /&gt;
     },&lt;br /&gt;
     bravo: func print(&amp;quot;\tBRAVO&amp;quot;),&lt;br /&gt;
     test:  func print(&amp;quot;\tthis is B.test&amp;quot;),&lt;br /&gt;
     write: func print(&amp;quot;\tmy value is: &amp;quot;, me.value),&lt;br /&gt;
 },&lt;br /&gt;
 &lt;br /&gt;
 var C = {                                            # class C that inherits ...&lt;br /&gt;
     new: func(v) {&lt;br /&gt;
         return { parents: [C, A.new(), B.new(v)] };  # ... from class A and B&lt;br /&gt;
     },&lt;br /&gt;
     charlie: func print(&amp;quot;\tCHARLIE&amp;quot;),&lt;br /&gt;
     test:    func print(&amp;quot;\tthis is C.test&amp;quot;),         # overrides A.test() and B.test()&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 print(&amp;quot;A instance&amp;quot;);&lt;br /&gt;
 var a = A.new();&lt;br /&gt;
 a.alpha();&lt;br /&gt;
 &lt;br /&gt;
 print(&amp;quot;B instance&amp;quot;);&lt;br /&gt;
 var b = B.new(123);&lt;br /&gt;
 b.bravo();&lt;br /&gt;
 b.write();&lt;br /&gt;
 &lt;br /&gt;
 print(&amp;quot;C instance&amp;quot;);&lt;br /&gt;
 var c = C.new(456);&lt;br /&gt;
 c.alpha();                        # use alpha from the A parent&lt;br /&gt;
 c.bravo();                        # use bravo from the B parent&lt;br /&gt;
 c.charlie();                      # use charlie from C itself&lt;br /&gt;
 c.test();                         # use C.test(), which overrides A.test() and B.test()&lt;br /&gt;
 c.write();&lt;br /&gt;
&lt;br /&gt;
Even if a class overrides a method of a parent with the same name, the parent's version can still be accessed via &amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt; vector.&lt;br /&gt;
&lt;br /&gt;
 c.test()               # use C.test()&lt;br /&gt;
 c.parents[0].test();   # use C.test()&lt;br /&gt;
 c.parents[1].test();   # use A.test()&lt;br /&gt;
 c.parents[2].test();   # use B.test()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== More on methods ===&lt;br /&gt;
&lt;br /&gt;
Methods are function members of a class hash. They can access other class members via the &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; variable, which is a reference to the class hash. For this reason, a method returning &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; can be used like the class itself, and one can apply further methods to the return value (this is usually called &amp;quot;method chaining&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
 var Object = {&lt;br /&gt;
     new: func(coords...) {&lt;br /&gt;
         return { parents: [Object], coords: coords };&lt;br /&gt;
     },&lt;br /&gt;
     rotate: func(angle) {&lt;br /&gt;
         # do the rotation&lt;br /&gt;
         return me;&lt;br /&gt;
     },&lt;br /&gt;
     scale: func(factor) {&lt;br /&gt;
         # do the scaling&lt;br /&gt;
         return me;&lt;br /&gt;
     },&lt;br /&gt;
     translate: func(x, y) {&lt;br /&gt;
         # do the translation&lt;br /&gt;
         return me;&lt;br /&gt;
     },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var triangle = Object.new([0, 0], [10, 0], [5, 7]);&lt;br /&gt;
 triangle.translate(-9, -4).scale(5).rotate(33).translate(9, 4);    # concatenated methods thanks to &amp;quot;me&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt;, however, is only known in the scope of the class. If a method is to be called as a listener callback or a timer function, &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; has to get wrapped in a function, so that it's stored in the function closure.&lt;br /&gt;
&lt;br /&gt;
 var Manager = {&lt;br /&gt;
     new: func {&lt;br /&gt;
         return { parents: [Manager] };&lt;br /&gt;
     },&lt;br /&gt;
     start_timers: func {  &lt;br /&gt;
         settimer(do_stuff, 5);            # BAD: there's no &amp;quot;do_stuff&amp;quot; function in the scope&lt;br /&gt;
         settimer(me.do_stuff, 5);         # BAD: function exists, but &amp;quot;me&amp;quot; won't be known&lt;br /&gt;
                                           #      when the timer function is actually executed&lt;br /&gt;
         settimer(func me.do_stuff(), 5);  # GOOD: new function object packs &amp;quot;me&amp;quot; in the closure&lt;br /&gt;
 &lt;br /&gt;
         setlistener(&amp;quot;/sim/foo&amp;quot;, func me.do_stuff());  # GOOD  (same as with timers) &lt;br /&gt;
     },         &lt;br /&gt;
     do_stuff: func {&lt;br /&gt;
         print(&amp;quot;doing stuff&amp;quot;);&lt;br /&gt;
     },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var manager = Manager.new();&lt;br /&gt;
 manager.start_timers();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Click ''[http://wiki.flightgear.org/Namespaces_and_Methods#Methods here]'' for more information.'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Exception handling ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;die()&amp;lt;/tt&amp;gt; aborts a function with an error message (this can be compared to the throw() mechanism in C++).&lt;br /&gt;
&lt;br /&gt;
 var divide = func(a, b) {&lt;br /&gt;
     if (b == 0)&lt;br /&gt;
         die(&amp;quot;division by zero&amp;quot;);&lt;br /&gt;
     return a / b;     # this line won't be reached if b == 0&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
die() is also used internally by built-in extension functions or Nasal core functions. &amp;lt;tt&amp;gt;getprop(&amp;quot;/4me&amp;quot;)&amp;lt;/tt&amp;gt;, for example, dies with an error message ''&amp;quot;name must begin with alpha or '_'&amp;quot;''. Now assume we want to write a dialog where the user can type a property path into an input field, and we display the property's value in a popup dialog. What if the user typed an invalid path and we hand that over to &amp;lt;tt&amp;gt;getprop()&amp;lt;/tt&amp;gt;? We don't want Nasal to abort our code because of that. We want to display a nice error message instead. The &amp;lt;tt&amp;gt;call()&amp;lt;/tt&amp;gt; function can catch &amp;lt;tt&amp;gt;die()&amp;lt;/tt&amp;gt; exceptions:&lt;br /&gt;
&lt;br /&gt;
 var value = getprop(property);                                    # dies if 'property' is invalid&lt;br /&gt;
 var value = call(func getprop(property), nil, var err = []);      # catches invalid-property-exception and continues&lt;br /&gt;
&lt;br /&gt;
The second line calls getprop(property) just like the first, and returns its value. But if 'property' was invalid then the &amp;lt;tt&amp;gt;call()&amp;lt;/tt&amp;gt; function catches the exception and sets the 'err' vector instead. That vector remains empty on success.&lt;br /&gt;
&lt;br /&gt;
 if (size(err))&lt;br /&gt;
     print(&amp;quot;ERROR: bad property &amp;quot;, property, &amp;quot; (&amp;quot;, err[0], &amp;quot;)&amp;quot;);   # err[0] contains the die() message&lt;br /&gt;
 else&lt;br /&gt;
     print(&amp;quot;value of &amp;quot;, property, &amp;quot; is &amp;quot;, value);&lt;br /&gt;
&lt;br /&gt;
The first argument of &amp;lt;tt&amp;gt;call()&amp;lt;/tt&amp;gt; is a function object, the second a vector of function arguments (or ''nil''), and the third a vector where the function will return a possible error. For more information on the &amp;lt;tt&amp;gt;call()&amp;lt;/tt&amp;gt; function see the [http://plausible.org/nasal/lib.html Nasal library documentation]. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;die()&amp;lt;/tt&amp;gt; doesn't really care about what its argument is. It doesn't have to be a string, and can be any variable, for example a class. This can be used to pass values through a chain of functions.&lt;br /&gt;
&lt;br /&gt;
 var Error = {                                                             # exception class&lt;br /&gt;
     new: func(msg, number) {&lt;br /&gt;
         return { parents: [Error], message: msg, number: number };&lt;br /&gt;
     },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var A = func(a) {&lt;br /&gt;
     if (a &amp;lt; 0)&lt;br /&gt;
         die(Error.new(&amp;quot;negative argument to A&amp;quot;, a));                      # throw Error&lt;br /&gt;
     return &amp;quot;A received &amp;quot; ~ a;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 var B = func(val) {&lt;br /&gt;
     var result = A(val);&lt;br /&gt;
     print(&amp;quot;B finished&amp;quot;);      # this line is not reached if A threw an exception&lt;br /&gt;
     return result;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 var value = call(B, [-4], var err = []);                                  # try B(-4)&lt;br /&gt;
 &lt;br /&gt;
 if (size(err)) {                                                          # catch (...)&lt;br /&gt;
     print(&amp;quot;ERROR: &amp;quot;, err[0].message, &amp;quot;; bad value was &amp;quot;, err[0].number);&lt;br /&gt;
     die(err[0]);                                                          # re-throw&lt;br /&gt;
 } else {&lt;br /&gt;
     print(&amp;quot;SUCCESS: &amp;quot;, value);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Listeners and Signals ==&lt;br /&gt;
&lt;br /&gt;
Listeners are callback functions that are attached to property nodes. They are triggered whenever the node is written to, or, depending on the listener type, also when children are added or removed, and when children are written to. Unlike polling loops, listeners don't have the least effect on the frame rate when they aren't triggered, which makes them preferable to monitor properties that aren't written to frequently. &lt;br /&gt;
&lt;br /&gt;
===setlistener() vs. _setlistener() ===&lt;br /&gt;
You are requested *not* to use the raw _setlistener() function, except in files in $FG_ROOT/Nasal/ when they are&lt;br /&gt;
needed immediately. Only then the raw function is required, as it doesn't rely on props.nas.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;tt&amp;gt;When listeners don't work&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Unfortunately, '''listeners don't work on so-called &amp;quot;tied&amp;quot; properties''' when the node value isn't set via property methods. (You can spot such tied properties by Ctrl-clicking the &amp;quot;.&amp;quot; entry in the property browser: they are marked with a &amp;quot;T&amp;quot;.) Most of the FDM properties are &amp;quot;tied&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Examples of properties where setlistener ''won't'' work: &lt;br /&gt;
&lt;br /&gt;
* /position/elevation-ft&lt;br /&gt;
* /ai/models/aircraft/orientation/heading-deg&lt;br /&gt;
* Any property node created as an alias&lt;br /&gt;
* Lots of others&lt;br /&gt;
&lt;br /&gt;
Before working to create a listener, always check whether a listener will work with that property node by control-clicking the &amp;quot;.&amp;quot; in property browser to put it into verbose mode, and then checking whether the property node for which you want to set up a listener is marked with a &amp;quot;T&amp;quot; or not.&lt;br /&gt;
&lt;br /&gt;
If you can't set a listener for a particular property, the alternative is to use settimer to set up a timer loop that checks the property value regularly. &lt;br /&gt;
&lt;br /&gt;
Listeners are most efficient for properties that change only occasionally.  No code is called at all during frames where the listener function is not called.  If the property value changes every frame, setting up a settimer loop with time=0 will execute every frame, just the same as setlistener would, and the settimer loop is more efficient than setting a listener. This is one reason the fact the setlistener doesn't work on certain tied and FDM properties is not a great loss.  See the section on timer loops below.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Syntax:&lt;br /&gt;
&lt;br /&gt;
 var listener_id = setlistener(&amp;lt;property&amp;gt;, &amp;lt;function&amp;gt; [, &amp;lt;startup=0&amp;gt; [, &amp;lt;runtime=1&amp;gt;]]);&lt;br /&gt;
&lt;br /&gt;
The first argument is a property node object (&amp;lt;tt&amp;gt;props.Node()&amp;lt;/tt&amp;gt; hash) or a property path. Because the node hash depends on the props.nas module being loaded, &amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; calls need to be deferred when used in an $FG_ROOT/Nasal/*.nas file, usually by calling them in a &amp;lt;tt&amp;gt;settimer(func {}, 0)&amp;lt;/tt&amp;gt; construction. To avoid that, one can use the raw &amp;lt;tt&amp;gt;_setlistener()&amp;lt;/tt&amp;gt; function directly, for which &amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; is a wrapper. The raw function does only accept node paths (e.g. &amp;quot;/sim/menubar/visibility&amp;quot;), but not props.Node() objects.&lt;br /&gt;
&lt;br /&gt;
The second argument is a function object (not a function call!). The &amp;lt;tt&amp;gt;func&amp;lt;/tt&amp;gt; keyword turns code into a function object.&lt;br /&gt;
&lt;br /&gt;
The third argument is optional. If it is non-null, then it causes the listener to be called initially. This is useful to let the callback function pick up the node value at startup.&lt;br /&gt;
&lt;br /&gt;
The fourth argument is optional, and defaults to 1. This means that the callback function will be executed whenever the property is written to, independent of the value. &lt;br /&gt;
&lt;br /&gt;
If the argument is set to 0, then the function will only get triggered if a value other than the current value is written to the node. This is important for cases where a property is written to once per frame, no matter if the value changed or not. YASim, for example, does that for /gear/gear/wow or /gear/launchbar/state.&lt;br /&gt;
So, this should be used for properties that are written to in every frame, although the written value is mostly the same. If the argument is 2, then also write access to children will get reported, as well as the creation and removal of children nodes.&lt;br /&gt;
&lt;br /&gt;
For both optional flags 0 means less calls, and 1 means more calls. The first is for startup behavior, and the second for runtime behavior.&lt;br /&gt;
&lt;br /&gt;
Here's a real-life example:&lt;br /&gt;
&lt;br /&gt;
  setlistener(&amp;quot;/gear/launchbar/state&amp;quot;, func {&lt;br /&gt;
      if (cmdarg().getValue() == &amp;quot;Engaged&amp;quot;)&lt;br /&gt;
          setprop(&amp;quot;/sim/messages/copilot&amp;quot;, &amp;quot;Engaged!&amp;quot;);&lt;br /&gt;
  }, 1, 0);&lt;br /&gt;
&lt;br /&gt;
YASim writes once per frame the string &amp;quot;Disengaged&amp;quot; to property /gear/launchbar/state. When an aircraft on deck of the aircraft carrier locks into the catapult, this changes to &amp;quot;Engaged&amp;quot;, which is then written again in every frame, until the aircraft leaves the catapult. Because the locking in is a bit difficult -- one has to target the sensitive area quite exactly --, it was desirable to get some quick feedback: a screen message that's also spoken by the Festival speech synthesis. With the args 1 and 0, this is done initially (for the unlikely case that we are locked in from the beginning), and then only when the node changes from an arbitrary value to &amp;quot;Engaged&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; returns a unique listener id on success, and &amp;lt;tt&amp;gt;nil&amp;lt;/tt&amp;gt; on error. The id is nothing else than a counter that is 0 for the first Nasal listener, 1 for the second etc. You need this id number to remove the listener. Most listeners are never removed, so that one doesn't assign the return value, but simply drop it.&lt;br /&gt;
&lt;br /&gt;
Listener callback functions can access up to four values via regular function arguments, the first two of which are property nodes in the form of a &amp;lt;tt&amp;gt;props.Node()&amp;lt;/tt&amp;gt; object hash.&lt;br /&gt;
&lt;br /&gt;
If you have set a callback function named ''myCallbackFunc'' via &amp;lt;tt&amp;gt;setlistener&amp;lt;/tt&amp;gt; (''setlistener(myNode, myCallbackFunc)''), you can use this syntax in the callback function:&lt;br /&gt;
&lt;br /&gt;
 myCallbackFunc ([&amp;lt;changed_node&amp;gt; [, &amp;lt;listened_to_node&amp;gt; [, &amp;lt;operation&amp;gt; [, &amp;lt;is_child_event&amp;gt;]]]])&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;removelistener()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Syntax:&lt;br /&gt;
&lt;br /&gt;
 var num_listeners = removelistener(&amp;lt;listener id&amp;gt;);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;removelistener()&amp;lt;/tt&amp;gt; takes one argument: the unique listener id that a &amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; call returned. It returns the number of remaining active Nasal listeners on success, &amp;lt;tt&amp;gt;nil&amp;lt;/tt&amp;gt; on error, or -1 if a listener function applies &amp;lt;tt&amp;gt;removelistener()&amp;lt;/tt&amp;gt; to itself. The fact that a listener can remove itself, can be used to implement a one-shot listener function:&lt;br /&gt;
&lt;br /&gt;
 var L = setlistener(&amp;quot;/some/property&amp;quot;, func {&lt;br /&gt;
     print(&amp;quot;I can only be triggered once.&amp;quot;);&lt;br /&gt;
     removelistener(L);&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Listener Examples ===&lt;br /&gt;
&lt;br /&gt;
The following example attaches an anonymous callback function to a &amp;quot;signal&amp;quot;. The function will be executed when FlightGear is closed.&lt;br /&gt;
&lt;br /&gt;
 setlistener(&amp;quot;/sim/signals/exit&amp;quot;, func { print(&amp;quot;bye!&amp;quot;) });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead of an anonymous function, a named function can be used as well:&lt;br /&gt;
&lt;br /&gt;
 var say_bye = func { print(&amp;quot;bye&amp;quot;) }&lt;br /&gt;
 setlistener(&amp;quot;/sim/signals/exit&amp;quot;, say_bye);&lt;br /&gt;
&lt;br /&gt;
Callback functions can, optionally, access up to four parameters which are handed over via regular function arguments. Many times none of these parameters is used at all, as in the above example.&lt;br /&gt;
&lt;br /&gt;
Most often, only the first parameter is used--which gives the node of the changed value.&lt;br /&gt;
&lt;br /&gt;
The following code attaches the monitor_course() function to a gps property, using the argument ''course'' to get the node with the changed value.&lt;br /&gt;
&lt;br /&gt;
 var monitor_course = func(course) {&lt;br /&gt;
     print(&amp;quot;Monitored course set to &amp;quot;, course.getValue());&lt;br /&gt;
 }&lt;br /&gt;
 var i = setlistener(&amp;quot;instrumentation/gps/wp/leg-course-deviation-deg&amp;quot;, monitor_course);&lt;br /&gt;
 &lt;br /&gt;
 # here the listener is active&lt;br /&gt;
 &lt;br /&gt;
 removelistener(i);                    # remove that listener again&lt;br /&gt;
&lt;br /&gt;
Here is code that accesses two arguments--the changed node and the listened-to node (these may be different when monitoring all children of a certain node)--and also shows how to monitor changes to a node including changes to children:&lt;br /&gt;
&lt;br /&gt;
 var monitor_course = func(course, flightinfo) {&lt;br /&gt;
     print(&amp;quot;One way to get the course setting: &amp;quot;, flightinfo.leg-course-deviation-deg.getValue());&lt;br /&gt;
     print(&amp;quot;Another way to get the same setting &amp;quot;, course.getValue());&lt;br /&gt;
 }&lt;br /&gt;
 var i = setlistener(&amp;quot;instrumentation/gps/wp&amp;quot;, monitor_course, 0, 2);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The function object doesn't need to be a separate, external function -- it can also be an anonymous function made directly in the &amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; call:&lt;br /&gt;
&lt;br /&gt;
 setlistener(&amp;quot;/sim/signals/exit&amp;quot;, func { print(&amp;quot;bye&amp;quot;) });    # say &amp;quot;bye&amp;quot; on exit&lt;br /&gt;
&lt;br /&gt;
Beware, however, that the contents of a function defined within the &amp;lt;tt&amp;gt;setlistener&amp;lt;/tt&amp;gt; call are not evaluated until the call is actually made. If, for instance, local variables change before the setlistener call happens, the call will reflect the current value of those variables ''at the time the callback function is called'', not the value ''at the time the listener was set''. &lt;br /&gt;
&lt;br /&gt;
For example, with this loop, the function will always return the value 10--even if mynode[1], mynode[2], mynode[3] or any of the others is the one that changed. It is because the contents of the setlistener are evaluated after the loop has completed running and at that point, i=10:&lt;br /&gt;
&lt;br /&gt;
 var output = func(number) {&lt;br /&gt;
     print(&amp;quot;mynode&amp;quot;, number, &amp;quot; has changed!&amp;quot;); #This won't work!&lt;br /&gt;
 }&lt;br /&gt;
 for(i=1; i &amp;lt;= 10; i = i+1) {&lt;br /&gt;
    var i = setlistener(&amp;quot;mynode[&amp;quot;~i~&amp;quot;]&amp;quot;, func{ output (i); });&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
You can also access the four available function properties (or just one, two, or three of them as you need) in your anonymous function. Here is an example that accesses the first value:&lt;br /&gt;
 &lt;br /&gt;
 for(i=1; i &amp;lt;= 10; i = i+1) {&lt;br /&gt;
    var i = setlistener(&amp;quot;mynode[&amp;quot;~i~&amp;quot;]&amp;quot;, func (changedNode) { print (changedNode.getPath() ~ &amp;quot; : &amp;quot; ~ changedNode.getValue()); });&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Attaching a function to a node that is specified as &amp;lt;tt&amp;gt;props.Node()&amp;lt;/tt&amp;gt; hash:&lt;br /&gt;
&lt;br /&gt;
 var node = props.globals.getNode(&amp;quot;/sim/signals/click&amp;quot;, 1);&lt;br /&gt;
 setlistener(node, func { gui.popupTip(&amp;quot;don't click here!&amp;quot;) });&lt;br /&gt;
&lt;br /&gt;
Sometimes it is desirable to call the listener function initially, so that it can pick up the node value. In the following example a listener watches the view number, and turns the HUD on in cockpit view, and off in all other views. It doesn't only do that on writing to &amp;quot;view-number&amp;quot;, but also once when the listener gets attached, thanks to the third argument &amp;quot;1&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 setlistener(&amp;quot;/sim/current-view/view-number&amp;quot;, func(n) {&lt;br /&gt;
     setprop(&amp;quot;/sim/hud/visibility[0]&amp;quot;, n.getValue() == 0);&lt;br /&gt;
 }, 1);&lt;br /&gt;
&lt;br /&gt;
There's no limit for listeners on a node. Several functions can get attached to one node, just as one function can get attached to several nodes. Listeners may write to the node they are listening to. This will not make the listener call itself causing an endless recursion.&lt;br /&gt;
&lt;br /&gt;
=== Signals ===&lt;br /&gt;
&lt;br /&gt;
In addition to &amp;quot;normal&amp;quot; nodes, there are &amp;quot;signal&amp;quot; nodes that were created solely for the purpose of having listeners attached:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/exit&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; on quitting FlightGear&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/reinit&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; right before resetting FlightGear (Shift-Esc), and to &amp;quot;false&amp;quot; afterwards&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/click&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; after a mouse click at the terrain. Hint that the geo coords for the click spot were updated and can be retrieved from /sim/input/click/{longitude-deg,latitude-deg,elevation-ft,elevation-m}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/screenshot&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; right before the screenshot is taken, and set to &amp;quot;false&amp;quot; after it. Can be used to hide and reveal dialogs etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/nasal-dir-initialized&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; after all Nasal &amp;quot;library&amp;quot; files in $FG_ROOT/Nasal/ were loaded and executed. It is only set once and can only be used to trigger listener functions that were defined in one of the Nasal files in that directory. After that signal was set&lt;br /&gt;
Nasal starts loading and executing aircraft Nasal files, and only later are &amp;lt;tt&amp;gt;settimer()&amp;lt;/tt&amp;gt; functions&lt;br /&gt;
called and the next signal is set:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/fdm-initialized&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; when then FDM has just finished its initialization&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/reinit-gui&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; when the GUI has just been reset (e.g. via Help menu). This&lt;br /&gt;
is used by the gui.Dialog class to reload Nasal-loaded XML dialogs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/frame&amp;lt;/tt&amp;gt; ... triggered at the beginning of each iteration of the main loop (a.k.a. &amp;quot;frame&amp;quot;). This is meant for debugging purposes. Normally, one would just use a settimer() with interval 0 for the same effect. The difference is that the signal is guaranteed to be raised at a defined moment, while the timer call may change when subsystems are re-ordered.&lt;br /&gt;
&lt;br /&gt;
== FlightGear extension functions ==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;cmdarg()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
cmdarg() is a mechanism to pass arguments to a nasal script (wrapped in properties) instead of &amp;quot;normal&amp;quot; function parameters. Note that cmdarg() should be primarily used in Nasal code embedded in XML files and should be considered depreciated otherwise (see [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg18361.html] and [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg18361.html]).&lt;br /&gt;
&lt;br /&gt;
cmdarg() will keep working in (joystick) XML-'''bindings''' and on the top-level of embedded Nasal scripts (i.e. dialog and animation XML files).&lt;br /&gt;
&lt;br /&gt;
As such, the cmdarg() function is primarily used for listener callbacks declared in XML markup, cmdarg() returns the listened-to property as props.Node object, so you can use it with all its methods (see $FG_ROOT/Nasal/props.nas) for example:&lt;br /&gt;
&lt;br /&gt;
  print(cmdarg().getPath(), &amp;quot; has been changed to &amp;quot;, cmdarg().getValue())&lt;br /&gt;
&lt;br /&gt;
The cmdarg() function avoids that you have to type the exact same path twice (once here and once in the setlistener() command) and it makes clear that this is the listened to property. Also, you can use all the nice props.Node methods on cmdarg() directly:&lt;br /&gt;
&lt;br /&gt;
 setlistener(&amp;quot;/gear/launchbar/state&amp;quot;, func {&lt;br /&gt;
      if (cmdarg().getValue() == &amp;quot;Engaged&amp;quot;)&lt;br /&gt;
          setprop(&amp;quot;/sim/messages/copilot&amp;quot;, &amp;quot;Engaged!&amp;quot;);&lt;br /&gt;
  }, 1, 0);&lt;br /&gt;
&lt;br /&gt;
Use of cmdarg() outside of XML-bindings won't cause an error, but (still) return the last cmdarg() property. This just won't be the listened-to property anymore, but whatever the last legitimate cmdarg() user set. Most of the time it will be the property root of a joystick binding.&lt;br /&gt;
&lt;br /&gt;
Don't make any assumptions and use cmdarg() only in one of these cases:&lt;br /&gt;
&lt;br /&gt;
* binding: returns root of this binding's property branch. Needed for accessing an axis' value:         cmdarg().getNode(&amp;quot;setting&amp;quot;).getValue()&lt;br /&gt;
&lt;br /&gt;
* dialog xml files: returns root of that file's property branch in memory. This can be used to let embedded Nasal change the dialog (e.g. clear and build lists) before the final layout is decided&lt;br /&gt;
&lt;br /&gt;
* animation xml files: returns root of this model's place in /ai/models/ when used as AI/MP model. Examples:       /ai/models/multiplayer[3], /ai/models/tanker[1], etc. [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg14164.html]&lt;br /&gt;
&lt;br /&gt;
* AI aircraft XML files&lt;br /&gt;
&lt;br /&gt;
* remotely invoking Nasal code by setting properties using the built-in telnet daemon (RPC) [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg00150.html [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg00336.html].&lt;br /&gt;
&lt;br /&gt;
'''In all cases, the cmdarg() call must not be delayed until later using settimer() or setlistener(). Because later it'll again return some unrelated property!&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;fgcommand()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Runs an internal &amp;quot;fgcommand&amp;quot;, see $FG_ROOT/Docs/README.commands for a list of available commands: http://gitorious.org/fg/fgdata/blobs/master/Docs/README.commands&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;print()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Concatenates an arbitrary number of arguments to one string, appends a new-line, and prints it to the terminal. Returns the number of printed characters.&lt;br /&gt;
&lt;br /&gt;
 print(&amp;quot;Just&amp;quot;, &amp;quot; a &amp;quot;, &amp;quot;test&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;getprop()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Returns the node value for a given path, or &amp;lt;tt&amp;gt;nil&amp;lt;/tt&amp;gt; if the node doesn't exist or hasn't been initialized yet. &lt;br /&gt;
&lt;br /&gt;
 getprop(&amp;lt;path&amp;gt;);&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 print(&amp;quot;The frame rate is &amp;quot;, getprop(&amp;quot;/sim/frame-rate&amp;quot;), &amp;quot; FPS&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;setprop()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Sets a property value for a given node path string. Always returns nil.&lt;br /&gt;
&lt;br /&gt;
 setprop(&amp;lt;path&amp;gt; [, &amp;lt;path&amp;gt;, [...]], &amp;lt;value&amp;gt;);&lt;br /&gt;
&lt;br /&gt;
All arguments but the last are concatenated to a path string, with a slash (/) inserted between each element. The last value is written to the respective node. If the node isn't writable, then an error message is printed to the console.&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;tt&amp;gt;setprop()&amp;lt;/tt&amp;gt; concatenates a list of input arguments by means of inserting a &amp;quot;/&amp;quot; in between. That is nice for properties, as this slash is part of the tree. However, when one wants to make use of indices, like [0], one has to concatenate by hand (using &amp;quot;~&amp;quot;) ''inside'' one part of the string argument list. An example is:&lt;br /&gt;
&lt;br /&gt;
  var i = 4;&lt;br /&gt;
  setprop(&amp;quot;instrumentation&amp;quot;,&amp;quot;cdu&amp;quot;,&amp;quot;page[&amp;quot;~i~&amp;quot;]&amp;quot;,&amp;quot;title&amp;quot;,&amp;quot;MENU&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This results in instrumentation/cdu/page[4]/title = 'MENU' (string)&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
 setprop(&amp;quot;/sim/current-view/view-number&amp;quot;, 2);&lt;br /&gt;
 setprop(&amp;quot;/controls&amp;quot;, &amp;quot;engines/engine[0]&amp;quot;, &amp;quot;reverser&amp;quot;, 1);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Erasing a property from the property tree''': a property that has been created, for example through &amp;lt;tt&amp;gt;setprop()&amp;lt;/tt&amp;gt; can be erased via&lt;br /&gt;
&lt;br /&gt;
  props.globals.getNode(&amp;quot;foo/bar&amp;quot;).remove(); 		# take out the complete node&lt;br /&gt;
  props.globals.getNode(&amp;quot;/foo&amp;quot;).removeChild(&amp;quot;bar&amp;quot;); 	# take out a certain child node&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;settimer()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Runs a function after a given simulation time (default) or real time in seconds.&lt;br /&gt;
&lt;br /&gt;
 settimer(&amp;lt;function&amp;gt;, &amp;lt;time&amp;gt; [, &amp;lt;realtime=0&amp;gt;]);&lt;br /&gt;
&lt;br /&gt;
The first object is a function object (ie, &amp;quot;func { ... }&amp;quot;).  Note that this is different from a function call (ie, &amp;quot;func ( ... )&amp;quot;). If you don't understand what this means, just remember to always enclose the first argument in any call to settimer with the word &amp;quot;func&amp;quot; and braces &amp;quot;{ }&amp;quot;, and it will always work. For instance, if you want print the words &amp;quot;My result&amp;quot; in five seconds, use this code:&lt;br /&gt;
&lt;br /&gt;
 settimer ( func { print ( &amp;quot;My result&amp;quot;); }, 5);&lt;br /&gt;
&lt;br /&gt;
Inside the braces of the func object you can put any valid Nasal code, including a function call.  In fact, if you want to call a function with certain values as arguments, the way to do it is to turn it into a function object by enclosing it with a func{}, for example:&lt;br /&gt;
&lt;br /&gt;
 myarg1=&amp;quot;My favorite string&amp;quot;;&lt;br /&gt;
 myarg2=432;&lt;br /&gt;
 settimer ( func { myfunction ( myarg1, myarg2); }, 25);&lt;br /&gt;
&lt;br /&gt;
The third argument is optional and defaults to 0, which lets the time argument be interpreted as &amp;quot;seconds simulation time&amp;quot;. In this case the timer doesn't run when FlightGear is paused. For user interaction purposes (measuring key press time, displaying popups, etc.) one usually prefers real time.&lt;br /&gt;
&lt;br /&gt;
 # simulation time example&lt;br /&gt;
 var copilot_annoyed = func { setprop(&amp;quot;/sim/messages/copilot&amp;quot;, &amp;quot;Stop it! Immediately!&amp;quot;) }&lt;br /&gt;
 settimer(copilot_annoyed, 10);&lt;br /&gt;
&lt;br /&gt;
 # real time example&lt;br /&gt;
 var popdown = func ( tipArg ) { &lt;br /&gt;
  fgcommand(&amp;quot;dialog-close&amp;quot;, tipArg); &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 var selfStatusPopupTip = func (label, delay = 10, override = nil) {	&lt;br /&gt;
    var tmpl = props.Node.new({&lt;br /&gt;
            name : &amp;quot;PopTipSelf&amp;quot;, modal : 0, layout : &amp;quot;hbox&amp;quot;,&lt;br /&gt;
            y: 140,&lt;br /&gt;
            text : { label : label, padding : 6 }&lt;br /&gt;
    });&lt;br /&gt;
    if (override != nil) tmpl.setValues(override);&lt;br /&gt;
    &lt;br /&gt;
    popdown(tipArgSelf);&lt;br /&gt;
    fgcommand(&amp;quot;dialog-new&amp;quot;, tmpl);&lt;br /&gt;
    fgcommand(&amp;quot;dialog-show&amp;quot;, tipArgSelf);&lt;br /&gt;
 &lt;br /&gt;
    currTimerSelf += 1;&lt;br /&gt;
    var thisTimerSelf = currTimerSelf;&lt;br /&gt;
 &lt;br /&gt;
    # Final argument 1 is a flag to use &amp;quot;real&amp;quot; time, not simulated time&lt;br /&gt;
    settimer(func { if(currTimerSelf == thisTimerSelf) { popdown(tipArgSelf) } }, delay, 1);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
[[Nasal_scripting_language#settimer_loops|More information about best practices for using the settimer function to create loops in Nasal is elsewhere on this page.]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;systime()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Returns epoch time (time since 1972/01/01 00:00) in seconds as a floating point number with high resolution. This is useful for benchmarking purposes.&lt;br /&gt;
&lt;br /&gt;
  #benchmarking example:&lt;br /&gt;
  var start = systime();&lt;br /&gt;
  how_fast_am_I(123);&lt;br /&gt;
  var end = systime();&lt;br /&gt;
  print(&amp;quot;took &amp;quot;, end - start, &amp;quot; seconds&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;carttogeod()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Converts cartesian coordinates x/y/z to geodetic coordinates lat/lon/alt, which are returned as a vector. Units are degree and meter.&lt;br /&gt;
&lt;br /&gt;
 var geod = carttogeod(-2737504, -4264101, 3862172);&lt;br /&gt;
 print(&amp;quot;lat=&amp;quot;, geod[0], &amp;quot; lon=&amp;quot;, geod[1], &amp;quot; alt=&amp;quot;, geod[2]);&lt;br /&gt;
 &lt;br /&gt;
 # outputs&lt;br /&gt;
 lat=37.49999782141546 lon=-122.6999914632327 alt=998.6042055172776&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;geodtocart()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Converts geodetic coordinates lat/lon/alt to cartesian coordinates x/y/z. Units are degree and meter.&lt;br /&gt;
&lt;br /&gt;
 var cart = geodtocart(37.5, -122.7, 1000); # lat/lon/alt(m)&lt;br /&gt;
 print(&amp;quot;x=&amp;quot;, cart[0], &amp;quot; y=&amp;quot;, cart[1], &amp;quot; z=&amp;quot;, cart[2]);&lt;br /&gt;
 &lt;br /&gt;
 # outputs&lt;br /&gt;
 x=-2737504.667684828 y=-4264101.900993474 z=3862172.834656495&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;geodinfo()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Returns information about geodetic coordinates. Takes two arguments: lat, lon (in degree) and returns a vector with two entries, or nil if no information could be obtained because the terrain tile wasn't loaded. The first entry is the elevation (in meters) for the given point, and the second is a hash with information about the assigned material, or nil if there was no material information available, because there is, for instance, an untextured building at that spot or the scenery tile is not loaded.&lt;br /&gt;
&lt;br /&gt;
 var lat = getprop(&amp;quot;/position/latitude-deg&amp;quot;);&lt;br /&gt;
 var lon = getprop(&amp;quot;/position/longitude-deg&amp;quot;);&lt;br /&gt;
 var info = geodinfo(lat, lon);&lt;br /&gt;
 &lt;br /&gt;
 if (info != nil) {&lt;br /&gt;
     print(&amp;quot;the terrain under the aircraft is at elevation &amp;quot;, info[0], &amp;quot; m&amp;quot;);&lt;br /&gt;
     if (info[1] != nil)&lt;br /&gt;
         print(&amp;quot;and it is &amp;quot;, info[1].solid ? &amp;quot;solid ground&amp;quot; : &amp;quot;covered by water&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A full data set looks like this:&lt;br /&gt;
&lt;br /&gt;
 debug.dump(geodinfo(lat, lon));&lt;br /&gt;
 &lt;br /&gt;
 # outputs&lt;br /&gt;
 [ 106.9892101062052, { light_coverage : 0, bumpiness : 0.5999999999999999, load_resistance : 1e+30,&lt;br /&gt;
 solid : 0,  names : [ &amp;quot;Lake&amp;quot;, &amp;quot;Pond&amp;quot;, &amp;quot;Reservoir&amp;quot;, &amp;quot;Stream&amp;quot;, &amp;quot;Canal&amp;quot; ], friction_factor : 1, &lt;br /&gt;
 rolling_friction : 1.5 } ]&lt;br /&gt;
&lt;br /&gt;
Note that geodinfo is a *very* CPU intensive operation, particularly in FG 2.4.0 and earlier, so use sparingly ([http://flightgear.org/forums/viewtopic.php?f=4&amp;amp;p=135044#p135044 discussion here]).&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;parsexml()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
This function is an interface to the built-in [http://expat.sourceforge.net/ Expat XML parser]. It takes up to five arguments. The first is a mandatory absolute path to an XML file, the remaining four are optional callback functions, each of which can be nil (which is also the default value).&lt;br /&gt;
&lt;br /&gt;
 var ret = parsexml(&amp;lt;path&amp;gt; [, &amp;lt;start-elem&amp;gt; [, &amp;lt;end-elem&amp;gt; [, &amp;lt;data&amp;gt; [, &amp;lt;pi&amp;gt; ]]]]);&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;start-elem&amp;gt;  ... called for every starting tag with two arguments: the tag name, and an attribute hash&lt;br /&gt;
 &amp;lt;end-elem&amp;gt;    ... called for every ending tag with one argument: the tag name&lt;br /&gt;
 &amp;lt;data&amp;gt;        ... called for every piece of data with one argument: the data string&lt;br /&gt;
 &amp;lt;pi&amp;gt;          ... called for every &amp;quot;processing information&amp;quot; with two args: target and data string&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;ret&amp;gt;         ... the return value is nil on error, and the &amp;lt;path&amp;gt; otherwise&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 var start = func(name, attr) {&lt;br /&gt;
     print(&amp;quot;starting tag &amp;quot;, name);&lt;br /&gt;
     foreach (var a; keys(attr))&lt;br /&gt;
         print(&amp;quot;\twith attribute &amp;quot;, a, &amp;quot;=&amp;quot;, attr[a]);&lt;br /&gt;
 }&lt;br /&gt;
 var end = func(name) { print(&amp;quot;ending tag &amp;quot;, name) }&lt;br /&gt;
 var data = func(data) { print(&amp;quot;data=&amp;quot;, data) }&lt;br /&gt;
 var pi = func(target, data) { print(&amp;quot;processing instruction: target=&amp;quot;, target, &amp;quot; data=&amp;quot;, data) }&lt;br /&gt;
 parsexml(&amp;quot;/tmp/foo.xml&amp;quot;, start, end, data, pi);&lt;br /&gt;
&lt;br /&gt;
=== airportinfo() ===&lt;br /&gt;
Function for retrieval of airport/runway information.&lt;br /&gt;
Usage:&lt;br /&gt;
&lt;br /&gt;
  var apt = airportinfo(&amp;quot;KHAF&amp;quot;);   # get info about KHAF&lt;br /&gt;
  var apt = airportinfo(lat, lon); # get info about apt closest to lat/lon&lt;br /&gt;
  var apt = airportinfo();         # get info about apt closest to aircraft  &lt;br /&gt;
&lt;br /&gt;
The command debug.dump(airportinfo(&amp;quot;KHAF&amp;quot;)) outputs this:&lt;br /&gt;
&lt;br /&gt;
  { lon : -122.4962626410256, lat : 37.51343502564102, has_metar : 0,&lt;br /&gt;
  runways : { 12 : { stopway2 : 0, threshold1 : 232.5624,&lt;br /&gt;
  lon : -122.5010889999999, lat : 37.513831, stopway1 : 0, width : 45.72,&lt;br /&gt;
  threshold2 : 232.5624, heading : 138.1199999999999, length : 1523.0856 } },&lt;br /&gt;
  elevation : 20.42159999999999, id : &amp;quot;KHAF&amp;quot;, name : &amp;quot;Half Moon Bay&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
That is: a hash with elements lat/lon/elev/id/name/has_metar for the&lt;br /&gt;
airport, and a hash with runways, each of which consists of lat/lon/&lt;br /&gt;
/length/width/heading/threshold[12]/stopway[12]. Only one side of each&lt;br /&gt;
runway is listed -- the other can easily be deduced.&lt;br /&gt;
&lt;br /&gt;
==Built-in functions==&lt;br /&gt;
&lt;br /&gt;
===sort(vector, function)===&lt;br /&gt;
Creates a new vector containing the elements in the input vector sorted in ascending order according to the rule given by function, which takes two arguments (elements of the input vector) and should return less than zero, zero, or greater than zero if the first argument is, respectively, less than, equal to, or greater than the second argument. Despite being implemented with ANSI C qsort(), the sort is stable; &amp;quot;equal&amp;quot; elements in the output vector will appear in the same relative order as they do in the input.&lt;br /&gt;
&lt;br /&gt;
Because you can define the sort function, sort allows you to create a list of keys sorting a hash by any criterion--by key, value, or (if, for instance the hash values are hashes themselves) any subvalue.&lt;br /&gt;
&lt;br /&gt;
 vec = [100,24,45];&lt;br /&gt;
 sortvec = sort (vec, func (a,b) cmp (a,b));&lt;br /&gt;
 debug.dump (sortvec); #output is [24,45,100]&lt;br /&gt;
&lt;br /&gt;
Here is an example of how to output the contents of a hash in sorted order.  Note that the function does not actually sort the hash but returns a list of the hash keys in sorted order.&lt;br /&gt;
&lt;br /&gt;
 var airport = {&lt;br /&gt;
   &amp;quot;LOXZ&amp;quot;: &amp;quot;Zeltweg&amp;quot;,&lt;br /&gt;
   &amp;quot;LOWI&amp;quot;: &amp;quot;Innsbruck&amp;quot;,&lt;br /&gt;
   &amp;quot;LOXL&amp;quot;: &amp;quot;Linz Hoersching&amp;quot;,     # the last comma is optional&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var sortedkeys= sort (keys(airport), func (a,b) cmp (airport[a], airport[b]));&lt;br /&gt;
 &lt;br /&gt;
 foreach (var i; sortedkeys) &lt;br /&gt;
  print (i, &amp;quot;: &amp;quot;, airport[i]);&lt;br /&gt;
&lt;br /&gt;
The output is:&lt;br /&gt;
&lt;br /&gt;
   LOWI: Innsbruck&lt;br /&gt;
   LOXL: Linz Hoersching&lt;br /&gt;
   LOXZ: Zeltweg  &lt;br /&gt;
&lt;br /&gt;
If the hash values are themselves hashes, sorting by any of the subvalues is possible.  For example:&lt;br /&gt;
&lt;br /&gt;
 var airport = {&lt;br /&gt;
    &amp;quot;LOXZ&amp;quot;: {city: &amp;quot;Zeltweg&amp;quot;, altitude_m: 1300 },&lt;br /&gt;
    &amp;quot;LOWI&amp;quot;: {city: &amp;quot;Innsbruck&amp;quot;, altitude_m: 2312 }, &lt;br /&gt;
    &amp;quot;LOXL&amp;quot;: {city: &amp;quot;Linz Hoersching&amp;quot;, altitude_m: 1932 },&lt;br /&gt;
 };&lt;br /&gt;
  &lt;br /&gt;
 #return a list of the hash keys sorted by altitude_m&lt;br /&gt;
 var sortedkeys= sort (keys(airport), func (a,b) airport[a].altitude_m - airport[b].altitude_m);&lt;br /&gt;
  &lt;br /&gt;
 foreach (var i; sortedkeys) &lt;br /&gt;
  print (i, &amp;quot;: &amp;quot;, airport[i].city, &amp;quot;, &amp;quot;, airport[i].altitude_m);&lt;br /&gt;
&lt;br /&gt;
Note that ''sort'' will return errors, and in FG 2.4.0 may even stop working, if the sort function you provide returns errors.  A common cause of this is if your sort vector contains both string and numeric values.  The cmp function will return an error for numeric values, and arithmetic operations you may use to sort numeric values will return errors if performed on a string.  The error in these cases is typically &amp;quot;function/method call on uncallable object&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Other useful built-in functions ===&lt;br /&gt;
&lt;br /&gt;
Other basic built-in Nasal functions such as append, setsize, subvec, typeof, contains, delete, int, num, keys, pop, size, streq, cmp, substr, sprintf, find, split, rand, call, die, bind, math.sin, math.pi, math.exp, math.ln math.e, io.read, io.write, regex.exec, and others of that sort, [http://www.plausible.org/nasal/lib.html are detailed in this external document].&lt;br /&gt;
&lt;br /&gt;
=== Useful functions in the Nasal directory ===&lt;br /&gt;
Other functions are available in the Nasal files found in the Nasal directory of a FlightGear install.  Simply open those Nasal files in text editor to see what is inside.  Reference those functions by putting the filename in front of the function, method, variable, or object you wish to use.  For instance, to use the method Coord.new() in the file geo.nas, you simply write:&lt;br /&gt;
&lt;br /&gt;
 geo.Coord.new()&lt;br /&gt;
&lt;br /&gt;
=== Distance calculations ===&lt;br /&gt;
&lt;br /&gt;
To calculate the distance between two points (in two different ways):&lt;br /&gt;
 # mylat1, mylong1, mylat2, mylong2 are lat &amp;amp; long in degrees &lt;br /&gt;
 # myalt1 &amp;amp; myalt2 are altitude in meters&lt;br /&gt;
 &lt;br /&gt;
 var GeoCoord1 = geo.Coord.new();&lt;br /&gt;
 GeoCoord1.set_latlon(mylat1, mylong1,myalt1);&lt;br /&gt;
 &lt;br /&gt;
 var GeoCoord2 = geo.Coord.new();&lt;br /&gt;
 GeoCoord2.set_latlon(mylat2, mylong2, myalt2);&lt;br /&gt;
 &lt;br /&gt;
 var directDistance = GeoCoord1.direct_distance_to(GeoCoord2);&lt;br /&gt;
 var surfaceDistance = GeoCoord1.distance_to(GeoCoord2);&lt;br /&gt;
&lt;br /&gt;
The results are distances in meters.&lt;br /&gt;
&lt;br /&gt;
* distance_to - returns distance in meters along Earth curvature, ignoring altitudes; useful for map distance&lt;br /&gt;
* direct_distance_to - returns distance in meters direct; considers altitude, but cuts through Earth surface&lt;br /&gt;
&lt;br /&gt;
=== Other useful geographical functions ===&lt;br /&gt;
Other useful geographical functions are found in geo.nas (in the FlightGear/data/Nasal directory of a FlightGear installation). geo.nas also includes documentation/explanation of the functions available.&lt;br /&gt;
&lt;br /&gt;
==Developing and debugging in Nasal==&lt;br /&gt;
===Developing Nasal code===&lt;br /&gt;
Because code in the Nasal directory is parsed only at Flightgear startup, testing and debugging Nasal code can by slow and difficult.&lt;br /&gt;
&lt;br /&gt;
Flightgear provides a couple of ways to work around this issue:&lt;br /&gt;
&lt;br /&gt;
====Nasal Console====&lt;br /&gt;
&lt;br /&gt;
The Nasal Console is available in Flightgear's menu (Debug/Nasal Console).  Selecting this menu opens a Nasal Console dialog.&lt;br /&gt;
&lt;br /&gt;
This dialog has several tabs, of which each can hold separate Nasal code snippets, all of which are saved on exit&lt;br /&gt;
and reloaded next time. This is useful for little tests, or for executing code for which writing a key binding is just too much&lt;br /&gt;
work, such as &amp;quot;props.dump(props.globals)&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
If you want to add more tabs (radio buttons in the Nasal Console dialog) to hold more code samples, just add more &amp;amp;lt;code&amp;amp;gt; nodes to autosave.xml.&lt;br /&gt;
&lt;br /&gt;
====Loading/reloading Nasal code without re-starting Flightgear====&lt;br /&gt;
A common problem in testing and debugging Nasal programs is that each testing step requires stopping and re-starting Flightgear, a slow process.&lt;br /&gt;
&lt;br /&gt;
Below is described a technique for loading and executing a Nasal file while Flightgear is running.  Flightgear will parse the file, display any errors in the Flightgear console window, and then execute the code as usual.&lt;br /&gt;
&lt;br /&gt;
Using this technique, you can start Flightgear, load the Nasal code you want to test observe any errors or test functionality as you wish, make changes to the Nasal file, reload it to observe parse errors or change in functionality, and so on to repeatedly and quickly run through the change/load/parse/test cycle without needing to re-start Flightgear each time.&lt;br /&gt;
&lt;br /&gt;
The key to this technique is the function io.load_nasal(), which loads a nasal file into a nasal namespace. &lt;br /&gt;
&lt;br /&gt;
Step-by-step instructions showing how to use this technique to load, parse, and test a Nasal file while Flightgear is running:&lt;br /&gt;
&lt;br /&gt;
=====Create the Nasal file to test=====&lt;br /&gt;
Create a text file named $FG_ROOT/foo/test.nas with this text:&lt;br /&gt;
  &lt;br /&gt;
  print(&amp;quot;hi!&amp;quot;);&lt;br /&gt;
  var msg=&amp;quot;My message.&amp;quot;;&lt;br /&gt;
  var hello = func { print(&amp;quot;I'm the test.hello() function&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
Notes: You can create the file in any directory you wish, as long as Nasal can read the directory--but the file IOrules in the Nasal directory restricts which directories Nasal may read and write from.  &lt;br /&gt;
&lt;br /&gt;
You can give the file any name and extension you wish, though it is generally most convenient to use the .nas extension with Nasal files.&lt;br /&gt;
&lt;br /&gt;
=====Load the file and test=====&lt;br /&gt;
Start Flightgear.  You can import the file above into Flightgear by typing the following into the Nasal Console dialog and executing the code:&lt;br /&gt;
&lt;br /&gt;
  io.load_nasal(getprop(&amp;quot;/sim/fg-root&amp;quot;) ~ &amp;quot;/foo/test.nas&amp;quot;, &amp;quot;example&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
getprop(&amp;quot;/sim/fg-root&amp;quot;) gets the root directory of the FlightGear installation, ~ &amp;quot;/foo/test.nas&amp;quot; appends the directory and filename you created.  The final variable &amp;quot;example&amp;quot; tells the namespace to load for the Nasal file.&lt;br /&gt;
&lt;br /&gt;
You'll see the message &amp;quot;hi!&amp;quot; on the terminal, and have function &amp;quot;example.hello()&amp;quot; immediately available. You can, for instance, type &amp;quot;example.hello();&amp;quot; into one of the Nasal console windows and press &amp;quot;Execute&amp;quot; to see the results; similarly you could execute &amp;quot;print (example.msg);&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
If you find errors or want to make changes, simply make them in your text editor, save the file, and execute the io.load_nasal() command again in the Nasal Console to re-load the file with changes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It's worth noting that Nasal code embedded in XML GUI dialog files can be reloaded by using the &amp;quot;debug&amp;quot; menu (&amp;quot;reload GUI&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
You may also want to check out the remarks on [[Nasal_scripting_language#Memory_management|Memory management]].&lt;br /&gt;
&lt;br /&gt;
==== Managing timers and listeners ====&lt;br /&gt;
&lt;br /&gt;
Note: If your Nasal program sets listeners, timer loops, and so on, they will remain set even when the code is reloaded, and reloading the code will set additional listeners and timer loops.  &lt;br /&gt;
&lt;br /&gt;
This can lead to extremely slow framerates and unexpected behavior.  For timers you can avoid this problem by using the loopid method (described above); for listeners you can create a function to destroy all timers your Nasal program creates, and call that function before reloading the program.  (And cleaning up timer loops and listeners is a best practice for creating Nasal programs in Flightgear regardless.)&lt;br /&gt;
&lt;br /&gt;
The same problem may occur while resetting or re-initializing parts of FlightGear if your code isn't prepared for this. And obviously this applies in particular also to any worker threads you may have started, too!&lt;br /&gt;
&lt;br /&gt;
For complex Nasal scripts with many timers and listeners, it is therefore generally a very good idea to implement special callbacks so that your scripts can respond to the most important simulator &amp;quot;signals&amp;quot;, this can be achieved by registering script-specific listeners to signals like &amp;quot;reinit&amp;quot; or &amp;quot;freeze&amp;quot; (pause): the corresponding callbacks can then suspend or re-initialize the Nasal code by suspending listeners and timers. Following this practice helps ensure that your code will behave properly even during simulator resets.&lt;br /&gt;
&lt;br /&gt;
In other words, it makes sense to provide a separate high-level controller routine to look for important simulator events and then pause or re-initialize your main Nasal code as required.&lt;br /&gt;
&lt;br /&gt;
If you are using [[Nasal_scripting_language#System-wide_Nasal_code|System-wide Nasal modules]], you should register listeners to properly re-initialize and clean up your Nasal code.&lt;br /&gt;
&lt;br /&gt;
In its simplest form, this could look like this:&lt;br /&gt;
&lt;br /&gt;
 var cleanup = func {}&lt;br /&gt;
 setlistener(&amp;quot;/sim/signals/reinit&amp;quot;, cleanup);&lt;br /&gt;
&lt;br /&gt;
This will invoke your &amp;quot;cleanup&amp;quot; function, whenever the &amp;quot;reinit&amp;quot; signal is set by the FlighGear core.&lt;br /&gt;
&lt;br /&gt;
Obviously, you now need to populare your cleanup function with some code, too.&lt;br /&gt;
&lt;br /&gt;
One of the easiest ways to do this, is removing all listeners/timers manually here, i.e. by adding calls to removelistener():&lt;br /&gt;
&lt;br /&gt;
 var cleanup = func {&lt;br /&gt;
  removelistener(id);&lt;br /&gt;
  removelistener(id);&lt;br /&gt;
  removelistener(id);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This would ensure that the corresponding listeners would be removed once the signal is triggered.&lt;br /&gt;
&lt;br /&gt;
On the other hand, you could just as well use a vector of listener IDs here, and then use a Nasal foreach loop:&lt;br /&gt;
&lt;br /&gt;
 var cleanup = func(id_list) {&lt;br /&gt;
  foreach(var id; id_list)&lt;br /&gt;
   removelistener(id);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Obviously, this would require that you maintain a list of active listeners, too - so that you can actually pass a list of IDs to the cleanup function.&lt;br /&gt;
&lt;br /&gt;
This is one of those things that can be easily done in Nasal, too - just by introducing a little helper wrapper:&lt;br /&gt;
&lt;br /&gt;
 var id_list=[];&lt;br /&gt;
 var store_listener = func(id) append(id_list,id);&lt;br /&gt;
&lt;br /&gt;
The only thing required here, would be replacing/wrapping the conventional &amp;quot;setlistener&amp;quot; call with calls to your helper:&lt;br /&gt;
&lt;br /&gt;
 store_listener( setlistener(&amp;quot;/sim/foo&amp;quot;) );&lt;br /&gt;
 store_listener( setlistener(&amp;quot;/foo/bar&amp;quot;) );&lt;br /&gt;
&lt;br /&gt;
If you were to do this consistently across all your Nasal code, you'd end up with a high level way to manage all your registered listeners centrally.&lt;br /&gt;
&lt;br /&gt;
Now, you'll probably have noticed that it would make sense to consider wrapping all these helpers and variables inside an enclosing helper class, this can be accomplished in Nasal using a hash. This would enable you to to implement everything neatly organized in an object and use RAII-like patterns to manage Nasal resources like timers, listeners and even threads.&lt;br /&gt;
&lt;br /&gt;
===Debugging===&lt;br /&gt;
The file debug.nas, included in the Nasal directory of the Flightgear distribution, has several functions useful for debugging Nasal code.  These functions are available to any Nasal program or code executed by Flightgear.&lt;br /&gt;
&lt;br /&gt;
Aside from those listed below, several other useful debugging functions are found in debug.nas; see the debug.nas file for the list of functions and explanation.&lt;br /&gt;
&lt;br /&gt;
Note that the debug module makes extensive use of ANSI terminal color codes.  These create colored output on Linux/Unix systems but on other systems they may add numerous visible control codes.  To turn off the color codes, go to the internal property tree and set&lt;br /&gt;
&lt;br /&gt;
 /sim/startup/terminal-ansi-colors=0&lt;br /&gt;
&lt;br /&gt;
Or within a Nasal program:&lt;br /&gt;
&lt;br /&gt;
 setprop (&amp;quot;/sim/startup/terminal-ansi-colors&amp;quot;,0);&lt;br /&gt;
&lt;br /&gt;
====debug.dump====&lt;br /&gt;
 debug.dump([&amp;lt;variable&amp;gt;])             ... dumps full contents of variable or of local variables if none given&lt;br /&gt;
 &lt;br /&gt;
The function debug.dump() dumps the contents of the given variable to the console. On Unix/Linux this is done with some syntax coloring. For example, these lines&lt;br /&gt;
&lt;br /&gt;
  var as = props.globals.getNode(&amp;quot;/velocities/airspeed-kt&amp;quot;, 1);&lt;br /&gt;
  debug.dump(as);&lt;br /&gt;
&lt;br /&gt;
would output&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/velocities/airspeed-kt=1.021376474393101 (DOUBLE; T)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;T&amp;quot; means that it's a &amp;quot;tied&amp;quot; property. The same letters are used here as in the property-browser. The angle brackets seem superfluous, but are useful because debug.dump() also outputs compound data types, such as vectors and hashes. For example:&lt;br /&gt;
&lt;br /&gt;
  var as = props.globals.getNode(&amp;quot;/velocities/airspeed-kt&amp;quot;, 1);&lt;br /&gt;
  var ac = props.globals.getNode(&amp;quot;/sim/aircraft&amp;quot;, 1);&lt;br /&gt;
  var nodes = [as, ac];&lt;br /&gt;
  var hash = { airspeed_node: as, aircraft_name: ac, all_nodes: nodes };&lt;br /&gt;
  debug.dump(hash);&lt;br /&gt;
&lt;br /&gt;
yields:&lt;br /&gt;
&lt;br /&gt;
  { all_nodes : [ &amp;lt;/velocities/airspeed-kt=1.021376474393101 (DOUBLE; T)&amp;gt;,&lt;br /&gt;
  &amp;lt;/sim/aircraft=&amp;quot;bo105&amp;quot; (STRING)&amp;gt; ], airspeed_node : &amp;lt;/velocities/airspe&lt;br /&gt;
  ed-kt=1.021376474393101 (DOUBLE; T)&amp;gt;, aircraft_name : &amp;lt;/sim/aircraft=&amp;quot;bo&lt;br /&gt;
  105&amp;quot; (STRING)&amp;gt; }&lt;br /&gt;
&lt;br /&gt;
====debug.backtrace====&lt;br /&gt;
  debug.backtrace([&amp;lt;comment:string&amp;gt;]}  ... writes backtrace with local variables&lt;br /&gt;
  debug.bt                             ... abbreviation for debug.backtrace&lt;br /&gt;
&lt;br /&gt;
The function debug.backtrace() outputs all local variables of the current function and all parent functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====debug.benchmark====&lt;br /&gt;
debug.benchmark(&amp;lt;label:string&amp;gt;, &amp;lt;func&amp;gt; [, &amp;lt;repeat:int&amp;gt;])&lt;br /&gt;
 ... runs function &amp;lt;repeat&amp;gt; times (default: 1) and prints execution time in seconds,prefixed with &amp;lt;label&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This is extremely useful for benchmarking pieces of code to determin &lt;br /&gt;
====debug.exit====&lt;br /&gt;
  debug.exit()                         ... exits fgfs&lt;br /&gt;
&lt;br /&gt;
== Related content ==&lt;br /&gt;
{{Forum|30|Nasal}}&lt;br /&gt;
* [[:Category:Nasal]]&lt;br /&gt;
&lt;br /&gt;
=== External links ===&lt;br /&gt;
* http://www.plausible.org/nasal&lt;br /&gt;
&lt;br /&gt;
[[Category:Nasal]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Nasal_scripting_language&amp;diff=38414</id>
		<title>Nasal scripting language</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Nasal_scripting_language&amp;diff=38414"/>
		<updated>2011-12-25T05:37:53Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Nasal = Not another scripting language! */ sentence correction&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''Please note that a considerable amount of resources has not yet been incorporated here, you can check these out by going to the &amp;quot;[[Talk:Nasal_scripting_language|discussion]]&amp;quot; page, where we are collecting links to webpages and mailing list discussions/postings related to Nasal.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nasal = Not another scripting language!==&lt;br /&gt;
&lt;br /&gt;
 The short summary is that Nasal is a scripting language that is tightly integrated with FlightGear itself, &lt;br /&gt;
 and provides a very easy way to manipulate the property tree, which is the core data structure within the &lt;br /&gt;
 simulator that exposes all the important internal runtime states of FlightGear. &lt;br /&gt;
&lt;br /&gt;
[[FlightGear]] offers a very powerful functional scripting language called [http://plausible.org/nasal/ &amp;quot;Nasal&amp;quot;], which supports reading and writing of internal [[Property Tree Intro|FlightGear properties]], accessing internal data via extension functions, creating GUI dialogs and much more. &lt;br /&gt;
&lt;br /&gt;
Nasal uses some of the concepts of ECMA/JavaScript, Python and Perl and implements a simple but complete way of Object Oriented Programming (OOP), Nasal uses an internal garbage collector so that no manual memory management is required by the programmer. &lt;br /&gt;
&lt;br /&gt;
People familiar with other programming languages, and scripting languages like JavaScript in particular, are usually able to learn Nasal rather quickly. FlightGear provides a rich library of simulation-specific and general-purpose functions that can be accessed by Nasal scripts.&lt;br /&gt;
&lt;br /&gt;
Nasal code can be run by aircraft configuration files, and it can be embedded in various [[XML]] files (dialog files, animation files, bindings for joysticks, keyboard and cockpit controls, and even in [[Howto: Nasal in scenery object XML files|scenery objects]]). Nasal is platform independent and designed to be thread safe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Some success stories ===&lt;br /&gt;
These were taken from the developers mailing list:&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Nasal is *very* well designed, compact, and efficient.  It is used heavily throughout many areas of FlightGear.&amp;quot;&lt;br /&gt;
* &amp;quot;It's interesting though how much nasal you can actually get away with using without making a blip on frame rates.  Nasal is *very* efficient and powerful for being an interpreted script language.&amp;quot;&lt;br /&gt;
* &amp;quot;FlightGear needed a built-in scripting language, and it has one. A compact, clean, elegant and fast one, Nasal extension functions interface perfectly to the property tree, the event manager, the built-in XML parser etc. Nasal is very tightly integrated in fgfs and used all over the place.&amp;quot;&lt;br /&gt;
* &amp;quot;There's no question that scripting languages are good; fgfs has a lot of Nasal code now. In my profiling I have never seen the nasal interpreter as a hot spot&amp;quot;&lt;br /&gt;
* &amp;quot;I'm a simple content contributor with very little background in programming. When I made my first Aircraft (the bf109) I was confronted with the need to deploy slats automatically at a given speed. I din't want to embed C++ code or had such a complex script that the error messages in FG wouldn't help me and I previously only used a bit of python. I looked at some Nasal scripts and within a few hours it worked. I was impressed how easy it is to write even complex Nasal scripts. Later I started developing the walker feature that made it possible to walk around in the scenery, all with nasal. Stuart kindly enhanced the walker and added an animation system to it (see bluebird), again with nasal. Others have made Flight computers with it (see V-22 and Su-37). Nasal is a worthy tool&amp;quot;&lt;br /&gt;
* &amp;quot;I used Nasal to build several rather complex systems, like Fuel System, Stab Augmentation System, Autopilot Logic, Terrain Avoidance Radar, Radar Warning Receiver and much more, and yes, I love Nasal too. Learning Nasal use was easy and fun and I din't found any limitation yet.&amp;quot;&lt;br /&gt;
* There are many vital parts of FlightGear currently coded in nasal.  There are also random bits of nasal code scattered around in joystick configurations, instrument and aircraft models, scenery models...  everywhere.&lt;br /&gt;
* &amp;quot;We have an entire directory full of Nasal 'function' libraries now, and I'm quite happy using them instead of rolling my own duplicate functionality.&amp;quot;&lt;br /&gt;
* Nearly every sophisticated Aircraft uses some kind of Nasal, be it Effects like tyre smoke or important functionalities like Engine and electric management, The Bluebird FDM is completely written in Nasal, vital parts of the V-22 Osprey rely on it, Flyby and Model View wouldn't work anymore, no more interactive objects in the scenery, lots of the MP System would be gone, ... Nasal is THE tool which makes FG development fun and adds nearly unlimited possibilities.  If you need an example, look at the Bluebird animated walker, all done in Nasal.&amp;quot;&lt;br /&gt;
* &amp;quot;there are good reasons to use Nasal - first of all the user base which regularly compiles their own code is small, whereas people do install addon packages - so I get a lot more feedback and test results. Second that one usually can't really crash the whole system from Nasal. Third, it's very easy to quickly try something and very maintenance-friendly. Fourth, you can actually start developing something without knowing how the core code ties together - which I suppose takes a lot of time to learn.  And so on.&amp;quot;&lt;br /&gt;
* &amp;quot;Hard-coding every instrument in C++ instead of nasal means only developers following/building the latest cvs  head code get to use whatever until the next release cycle.&amp;quot;&lt;br /&gt;
* &amp;quot;Hard coding every instrument/flight control in C++ means my WW-II storch (et.al.) is stuck with an autobrake functionality it doesn't have nor need.&amp;quot;&lt;br /&gt;
* &amp;quot;I think it boils down to the fact that we have two approaches that can accomplish the same thing.  The C/C++ approach offers high performance but there is a dependence on when the C/C++ code was added to FlightGear.  The Nasal approach offers fast prototyping, flexibility, and more (but not complete) independence from the C/C++ code.&amp;quot;&lt;br /&gt;
* &amp;quot;A basic problem with C++ functions is it is hard/impossible to override them for a special purpose. Writing in pure nasal allows function name hijacking and other tricks that can't be used on C++ code.&amp;quot;&lt;br /&gt;
* &amp;quot;Given the fact that FG is platform independent, I don't know if the embedded C++ is doing the same on Windows, Linux, PPC and intel Macs. Apart from the fact that if I was able to code c++ I would embed it to FG rather than in an Aircraft specific script&amp;quot;&lt;br /&gt;
* &amp;quot;If we ported Nasal code over to C++ we'd lose the ability to change small things &amp;quot;on the fly&amp;quot; without compiling over and over again. We'd also lose good programmers, who prefer scripting over C++. Aircraft creation would not be customizable etc etc.&amp;quot;&lt;br /&gt;
* &amp;quot;The argument against Nasal is essentially that C++ is faster than Nasal - which, everything else being equal, is certainly correct. But highly specialized Nasal code written for a particular problem outperforms general  purpose C++ code - I've given several examples in the past. If someone were e.g. to add movement to Nasal spawned models by adding a velocity property, I'm not sure it would outperform my Nasal quadtree-sorted adaptive range code which priorizes movement for things actually inside the field of view. Of course, if you'd hard-code that specialized algorithm, it would be faster than the Nasal version - but then you couldn't apply it to other problems any more.&amp;quot;&lt;br /&gt;
* &amp;quot;How many airplane developer will you loose if you remove the Nasal engine from FGFS because they can write Nasal code but not C++ code?&amp;quot;&lt;br /&gt;
* &amp;quot;The algorithm being equal, I don't think there's a question that C++ is faster (I doubt the factor 10 though - that seems to be an extreme case). Everything else being equal, I also don't think there's a question that Nasal code is more accessible. And I would base any decision what to hard-code and what not on that balance.&amp;quot;&lt;br /&gt;
* &amp;quot;Nasal is just much better suited for FlightGear than many alternatives because of it's size, processing speed and because a number of FlightGear core developers have a good idea what's going on.&amp;quot;&lt;br /&gt;
* &amp;quot;In theory we could even use VBScript but Nasal has proven to be valuable for almost 10 years, so no reason to change or add another scripting language. Besides, if you know JavaScript then learning Nasal would take little effort.&amp;quot;&lt;br /&gt;
* &amp;quot;The pool of people with commit rights to the core C++ code is very, very small.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nasal really is an excellent choice for prototyping and implementing new features and even completely new systems in FlightGear. &lt;br /&gt;
&lt;br /&gt;
For example, the [[bombable]] script implements &amp;quot;dog fighting&amp;quot; support on top of FlightGear, without ANY changes to the C++ side of the code, just by using some fairly advanced scripted code (implemented in the built-in Nasal programming language). You can basically imagine it like a &amp;quot;MOD&amp;quot; of FlightGear. In other words, the bombable script creates a completely new &amp;quot;mode&amp;quot; in FlightGear.&lt;br /&gt;
&lt;br /&gt;
No matter if it's scenery, aircraft, AI scenarios or whatever: many things that were originally never planned to be supported by FlightGear core developers, are now implicitly supported because of the lose coupling between highly configurable and flexible systems, such as the property tree and the Nasal scripting language.&lt;br /&gt;
&lt;br /&gt;
So we are really standing on the shoulders of giants here, because we are now -after 10+ years- in the position to create significant new features (and even completely new systems in FlightGear) within the constraints of the FlightGear base package, without even touching the C++ source code at all - simply because FlightGear has become so flexible and extensible.&lt;br /&gt;
&lt;br /&gt;
All of this became possible by some important architectural decisions, such as for example the use of XML and plain text files for pretty much all configuration files in FlightGear (and thus open file formats in general), a publicly accessible tree of state variables that can be easily inspected and modified at runtime (the property tree). Similarly, the decision to embed a scripting language that can be used for scripting the entire simulator was another important decision.&lt;br /&gt;
&lt;br /&gt;
In FlightGear, Nasal is the most accessible method of customizing the whole simulator to a very high degree. Nasal code can be easily edited using a conventional text editor, there are no special tools required: Nasal source code is interpreted, compiled to bytecode and run by the Nasal &amp;quot;virtual machine&amp;quot; using FlightGear itself. &lt;br /&gt;
&lt;br /&gt;
The emerging [[A local weather system|Local weather]] system was entirely prototyped in Nasal space, and is now being increasingly augmented by moving performance-critical functions to C++ space instead.&lt;br /&gt;
&lt;br /&gt;
Using Nasal, it is even possible to create entirely scripted flights and smart &amp;quot;AI bots&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 I have something here that I think is kind of fun.  I've been fiddling with&lt;br /&gt;
 this off and on since last fall and decided it was time to clean it up a bit&lt;br /&gt;
 and quit hording all the fun for myself.  Basically I have taken the F-14b&lt;br /&gt;
 and created a high performance Navy &amp;quot;drone&amp;quot; out of it.  It can auto-launch&lt;br /&gt;
 from a carrier, auto fly a route (if you've input one) and can do circle&lt;br /&gt;
 holds (compensating for wind.)  I've added a simulated&lt;br /&gt;
 gyro stabilized camera that will point at anything you click on and then&lt;br /&gt;
 hold that view steady no matter what the airplane does (similar to what real&lt;br /&gt;
 uav's can do.)  Finally, you can command it to return home and it will find&lt;br /&gt;
 the carrier, setup a reasonable approach and nail the landing perfectly&lt;br /&gt;
 every time (factoring in wind, carrier speed, etc.): http://www.flightgear.org/uas-demo/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As of 03/2009, there were approximately 170.000 lines of reported Nasal source code in the FlightGear base package [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg21333.html], compared to 2006 this is almost a rate of growth of 600% within 3 years [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg01728.html]. This illustrates the sheer adoption rate Nasal is experiencing in FlightGear.&lt;br /&gt;
&lt;br /&gt;
(As of 10/2011, the FlightGear base package contained 326.000 lines of Nasal source code in *.nas files)&lt;br /&gt;
&lt;br /&gt;
Note that this page is mostly about FlightGear-specific APIs/extension functions and usage patterns. &lt;br /&gt;
Thus, you may also want to have a look here:&lt;br /&gt;
&lt;br /&gt;
* [http://plausible.org/nasal/lib.html core language/library documentation] &lt;br /&gt;
* [http://plausible.org/nasal/sample.nas annotated source code examples]&lt;br /&gt;
* [http://plausible.org/nasal/doc.html Nasal design document]&lt;br /&gt;
* [http://www.plausible.org/nasal/flightgear.html a helpful tutorial about using Nasal in FlightGear].&lt;br /&gt;
&lt;br /&gt;
In addition, the [http://gitorious.org/fg/fgdata/trees/master/Nasal Nasal directory] in the FlightGear base package contains a wealth of tested, proven and usually well-commented source code that you may want to check out for additional examples of using the Nasal scripting language in FlightGear [http://gitorious.org/fg/fgdata/trees/master/Nasal].&lt;br /&gt;
&lt;br /&gt;
If you have any Nasal specific questions, you will want to check out the [[Nasal FAQ]], feel free to ask new questions or help answer or refine existing ones. If you would like to learn more about existing Nasal modules in FlightGear, you may want to check out [[Nasal Modules]].&lt;br /&gt;
&lt;br /&gt;
If you are a developer and interested in extending Nasal, you may want to check out [[Howto:Extending Nasal]].&lt;br /&gt;
&lt;br /&gt;
Many short &amp;quot;howto&amp;quot;-style tutorials on Nasal programming can be found in the [[Category:Nasal|Nasal category]].&lt;br /&gt;
&lt;br /&gt;
== Some words on Nasal for fellow C++ programmers ==&lt;br /&gt;
&lt;br /&gt;
Compared to C++, there is really nothing &amp;quot;low quality&amp;quot; about Nasal per se: Nasal is just the &amp;quot;script glue&amp;quot; that connects different parts of the simulator: Many Nasal scripts leverage C++ code - and it is very easy to add new C++ code that can be called from Nasal. &lt;br /&gt;
&lt;br /&gt;
History has shown, that most code in FlightGear will eventually be made more configurable and more accessible, this usually happens in the same steps: 1) replacing static variables with variables stored in the property tree, 2) using listeners to get update notifications for important variables, 3) fully exposing a &amp;quot;control&amp;quot; interface by making it accessible it in the property tree, 4) providing scripting hooks.&lt;br /&gt;
&lt;br /&gt;
Even if you should know C or C++ already, Nasal probably remains the most accessible and the most powerful method for customizing the simulator, simply because it is extremely easy and fast to get started, you don't need an &amp;quot;integrated development environment&amp;quot;, you don't need to install compilers and you don't need to satisfy any 3rd party dependencies; bottom line being: if you can run FlightGear, you can also run Nasal and create new code.&lt;br /&gt;
&lt;br /&gt;
In addition, Nasal code is fairly abstract code, too. Once you start looking at some existing Nasal scripts, you will see that it is also fairly high level code, much more high level than C++ - so Nasal has a much higher density of code, too. Nasal's role in FlightGear really is like JavaScript's role in Firefox, where it is also used for many/most core-related logics (CSS/XUL). &lt;br /&gt;
&lt;br /&gt;
=== Performance ===&lt;br /&gt;
&lt;br /&gt;
Obviously, C++ code will usually be faster than the corresponding Nasal code. But, while performance is not a design goal, Nasal isn't especially slow either. For example, early benchmarks of the garbage collector showed it as faster than perl's reference counter, and its number crunching performance is on par with python. But in all cases, simplicity, transparency and a sane feature set are preferred over speed in Nasal. &lt;br /&gt;
&lt;br /&gt;
Nasal was specifically designed for use as an extension language in an larger project such as FlightGear. The problem with many otherwise excellent languages in this environment is that they are huge. Perl and python are great, but enormous. Even their &amp;quot;core&amp;quot; interpreters and library code are larger than most projects that require an embedded language. They cannot be readily shipped with their host application and need to be installed system-wide. This is a pain and a compatibility hassle. &lt;br /&gt;
&lt;br /&gt;
The real goal with Nasal is to have a language that supports most &amp;quot;normal&amp;quot; programming idioms (objects, functions, arrays, hashes) while avoiding the bloat that comes from &amp;quot;platform&amp;quot; scripting languages like perl, python, ruby and php.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Garbage collection ===&lt;br /&gt;
Nasal garbage collects runtime storage, so the programmer need not worry about manual allocation, or even circular references. The current implementation is a simple mark/sweep collector, which should be acceptable for most applications. Future enhancements will include a &amp;quot;return early&amp;quot; capability for latency-critical applications. The collector can be instructed to return after a certain maximum delay, and be restarted later. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As far as speed goes, the last any benchmarking Nasal was done, it was about as fast as Perl 5 or Python 2.2 at most things.  It's garbage collector was faster, its symbol lookup about the same or slightly faster, and its bytecode interpreter somewhat slower.&lt;br /&gt;
&lt;br /&gt;
=== Thread safety ===&lt;br /&gt;
Unlike almost all other script interpreters (and unlike the FlightGear/Nasal interface itself) , Nasal is thread safe and scalable when called from multiple CPU threads (as opposed to the userspace interpreter threads implemented by Ruby). &lt;br /&gt;
&lt;br /&gt;
No special treatment is required (as for perl, which clones a separate interpreter with separate data for each thread and uses locking around specifically-designated shared data) and the threads can be scheduled simultaneously. There is no global lock on the interpreter, as used by Python or Lua. The only limit on scalability is garbage collection, which must block all interpreter threads before running. &lt;br /&gt;
&lt;br /&gt;
When running threaded code, Nasal provides &amp;quot;minimal threadsafety&amp;quot;, meaning that the interpreter itself can be safely called from multiple CPU threads without risk of corrupting or deadlocking the interpreter internals. Multithreaded operations are therefore &amp;quot;safe&amp;quot;, although they are not guaranteed to be atomic. In particular, poorly synchronized insertions into containers can &amp;quot;drop&amp;quot; objects into oblivion (which is OK from an interpreter stability standpoint, since the GC will clean them up normally). Nasal itself provides no synchronization primitives to address this; thread architecture is a &amp;quot;top-level&amp;quot; design job, and Nasal is intended to be an extension language in a larger project. Choice of synchronization mechanisms is going to be highly application dependent. &lt;br /&gt;
&lt;br /&gt;
=== Exception handling ===&lt;br /&gt;
Like python, nasal supports exception handling as a first-class language feature, with built-in runtime-inspectable stack trace. Rather like perl, however, there is no special &amp;quot;try&amp;quot; syntax for exception handling, nor inheritance-based catching semantics. Instead, you use the call() builtin to invoke a function object and inspect the results to determine what error was thrown (either with the die() builtin or via an internal runtime error) and what the stack trace looked like. Elaborate exception handling isn't really appropriate for embedded scripting languages.&lt;br /&gt;
&lt;br /&gt;
=== High level programming ===&lt;br /&gt;
&lt;br /&gt;
Thus, programmers already familiar with C++ shouldn't just disregard Nasal as a &amp;quot;toy&amp;quot; that doesn't seem suitable for serious development: some of the more complex Nasal scripts can literally make one's head spin around and it would quite obviously take much more C++ or Java code to implement the same features, while sacrificing all the flexibility and power that a scripting language offers. &lt;br /&gt;
&lt;br /&gt;
Some features can certainly be more easily implemented in Nasal space, than in C++ space. Often, the Nasal solution is &amp;quot;on par&amp;quot; with similar solutions in C++.&lt;br /&gt;
&lt;br /&gt;
=== Accessibility ===&lt;br /&gt;
&lt;br /&gt;
For instance, Nasal code cannot only be easily run and contributed by all users, but it can also be easily reused and maintained by other users. This means, that given the number of active C++ developers, compared to the number of base package contributors, your Nasal code is more likely to be actively maintained by fellow users if it is written in Nasal. &lt;br /&gt;
&lt;br /&gt;
In other words, if there are some experimental features you'd like to explore, Nasal is an excellent way to ensure that other FlightGear '''users''' can easily test your new features. This could be witnessed during the development of the local weather system or the bombable addon,too.&lt;br /&gt;
&lt;br /&gt;
This is in stark contrast to features developed solely in C++ space, because these can usually only be tested by people able to build FlightGear from source, especially if your code isn't yet in the main repository, where it would eventually be available in the form of a binary snapshot.&lt;br /&gt;
&lt;br /&gt;
Obviously, none of this is to say that Nasal is the perfect solution for any problem, there are many things for which Nasal isn't necessarily a perfect choice, such as low level code for example (i.e. rendering).&lt;br /&gt;
&lt;br /&gt;
On the other hand, Nasal really is a powerful tool in FlightGear, and if you find that something should, but cannot, be done in Nasal space, it is extremely easy to add support for new features to the Nasal engine using extension functions or property listeners to trigger C/C++ code.&lt;br /&gt;
&lt;br /&gt;
== Creating new Scripts ==&lt;br /&gt;
&lt;br /&gt;
Nasal scripts need to be plain text files, saved with a *.nas extension.&lt;br /&gt;
&lt;br /&gt;
=== Aircraft specific Nasal code ===&lt;br /&gt;
&lt;br /&gt;
Generally, aircraft specific Nasal scripts reside in the corresponding aircraft's folder (or a corresponding /Nasal subfolder) where they are usually included by adding a corresponding &amp;lt;nasal&amp;gt; tag to the aircraft-set.xml file (see [[Writing_simple_scripts_in_%22nasal%22|Writing simple scripts in &amp;quot;nasal&amp;quot;]]). Also see the section on [[Nasal_scripting_language#Namespaces|namespaces]] which contains more specific examples.&lt;br /&gt;
&lt;br /&gt;
=== Instrument specific Nasal code ===&lt;br /&gt;
&lt;br /&gt;
While instrument specific scripts are saved within the instrument's folder (as previously mentioned, Nasal scripts can also be embedded in various other XML files), Nasal scripts driving shared instruments are generally stored in [[$FG ROOT]]/Aircraft/Generic/&lt;br /&gt;
&lt;br /&gt;
=== Nasal code as bindings in XML files ===&lt;br /&gt;
Nasal scripts can also be used as &amp;quot;binding&amp;quot; objects, and can therefore appear anywhere in a configuration file (keyboard, mouse and joystick bindings, etc...) that accepts a &amp;lt;binding&amp;gt; tag. The relevant command type is &amp;quot;nasal&amp;quot;, and you place your Nasal code inside of the &amp;lt;script&amp;gt; tag: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;binding&amp;gt;&lt;br /&gt;
  &amp;lt;command&amp;gt;nasal&amp;lt;/command&amp;gt;&lt;br /&gt;
  &amp;lt;script&amp;gt;&lt;br /&gt;
   print(&amp;quot;Binding Invoked!&amp;quot;);&lt;br /&gt;
  &amp;lt;/script&amp;gt;&lt;br /&gt;
 &amp;lt;/binding&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code above invokes the print() function. This is a simple extension function that simply prints out its arguments, in order, to the FlightGear console as a single-line log entry. It is useful for debugging, but little else. &lt;br /&gt;
&lt;br /&gt;
=== System-wide Nasal code ===&lt;br /&gt;
&lt;br /&gt;
Nasal scripts that are not specific to certain aircraft, instruments or other uses, generally reside in the system-wide [[$FG ROOT]]/Nasal directory.&lt;br /&gt;
&lt;br /&gt;
Nasal scripts that are placed inside [[$FG ROOT]]/Nasal (with a *.nas extension) are automatically loaded and run during FlightGear startup. &lt;br /&gt;
&lt;br /&gt;
=== Nasal sub modules ===&lt;br /&gt;
&lt;br /&gt;
As of 06/2011, FlightGear also supports so called Nasal &amp;quot;sub modules&amp;quot; which may reside in their own sub folder under $FG_ROOT/Nasal/ and which provide support for on-demand loading at runtime by toggling properties.&lt;br /&gt;
&lt;br /&gt;
Some advantages are:&lt;br /&gt;
&lt;br /&gt;
* Nasal files can be grouped neatly instead of all scripts being mixed up in a single fgdata/Nasal directory. Grouping makes a lot of sense for modules consisting of several scripts - local weather is the best example.&lt;br /&gt;
* Guaranteed loading sequence. Submodules are loaded _after_ the main fgdata/Nasal scripts, so they can rely on all fgdata/Nasal content to be already present. No more need for awkward listener callbacks, just to make sure that basic &amp;quot;props&amp;quot; or &amp;quot;gui&amp;quot; modules are available.&lt;br /&gt;
* Finally, users have the option to disable loading modules. Unfortunately, just loading scripts (code/data) into memory already causes certain _run-time_ performance effects - even if the Nasal code was never executed (so even when all listeners/timers were disabled).&lt;br /&gt;
&lt;br /&gt;
Please note that there is  a difference between the _individual_ Nasal files in fgdata/Nasal and files belonging to a common Nasal _module in general (no matter whether loaded at run-time or loaded at start-up using a &amp;quot;&amp;lt;nasal&amp;gt;&amp;quot; tag).&lt;br /&gt;
&lt;br /&gt;
The individual Nasal files in fgdata/Nasal have an own namespace _each_. The namespace get's the name of the Nasal file itself. So if you have a &amp;quot;gui.nas&amp;quot; in the directory, then you can reference a symbol &amp;quot;foo&amp;quot; using &amp;quot;gui.foo&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Nasal modules also have a single namespace. But all files belonging to the module share this _single_ namespace. The name of their namespace is made from its directory (for the run-time loadable modules), or from the specific tag given below the &amp;lt;nasal&amp;gt; XML element, which are often used for a/c specific modules (e.g. &amp;lt;nasal&amp;gt;&amp;lt;ufo&amp;gt;...&amp;lt;/ufo&amp;gt;&amp;lt;/nasal&amp;gt; creates the ufo Nasal namespace in ufo-set.xml).&lt;br /&gt;
&lt;br /&gt;
'''So each Nasal file in a new Nasal &amp;quot;module&amp;quot; folder now shares the same namespace.'''&lt;br /&gt;
&lt;br /&gt;
For more information on Nasal sub modules, please see [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg32657.html] and [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg33458.html].&lt;br /&gt;
&lt;br /&gt;
=== User specific Nasal scripts ===&lt;br /&gt;
&lt;br /&gt;
It's also possible to put Nasal files into $FG_HOME/Nasal/, that is: ~/.fgfs/Nasal/ on Unix, and %APPDATA%\flightgear.org\Nasal\ on MS Windows. This has the following advantages:&lt;br /&gt;
&lt;br /&gt;
* one doesn't have to mix local extensions with standard files&lt;br /&gt;
* one is less likely to lose such local additions when upgrading&lt;br /&gt;
* one doesn't need write permission to $FG_ROOT/Nasal/ or&lt;br /&gt;
* one doesn't have to become &amp;quot;root&amp;quot; to edit such files&lt;br /&gt;
&lt;br /&gt;
The files are guaranteed to be read after all the files in $FG_ROOT/Nasal/, so one can safely use elements of files like props.nas (props.Node), or globals.nas (setlistener() without leading underscore).&lt;br /&gt;
&lt;br /&gt;
The files are guaranteed to be read in alphabetic order. So, if there are two files where one depends on the other, just name them appropriately.&lt;br /&gt;
&lt;br /&gt;
The contents of each file are added to a namespace derived from the filename. So, all functions and variables of a file ~/.fgfs/nasal/local.nas will be added to nasal namespace &amp;quot;local&amp;quot;, and a function test() is globally accessible as local.test().&lt;br /&gt;
&lt;br /&gt;
It's possible to extend a standard module like &amp;quot;math&amp;quot; with definitions in ~/.fgfs/Nasal/math.nas, though this should, of course, not be exploited by code that is to be submitted to cvs.&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
&lt;br /&gt;
A simple hello world example in Nasal would be:&lt;br /&gt;
&lt;br /&gt;
 # hello.nas&lt;br /&gt;
 print('Hello World!');&lt;br /&gt;
&lt;br /&gt;
This will show the &amp;quot;Hello World&amp;quot; string during startup in the console window. The hash sign (#) just introduces comments (i.e. will be ignored by the interpreter).&lt;br /&gt;
&lt;br /&gt;
Note: Script-specific symbols such as global variables (or functions) will be put into a scope (namespace) based on the script's name, scripts embedded via aircraft-set.xml files can separately specify a corresponding module name (see [[Howto: Make an aircraft]] for details).&lt;br /&gt;
&lt;br /&gt;
Strings in Nasal can also use double quotes which support escaping:&lt;br /&gt;
 # hello.nas&lt;br /&gt;
 print(&amp;quot;Hello\nWorld!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Double quotes support typical escape sequences:&lt;br /&gt;
&lt;br /&gt;
* \n 	Newline&lt;br /&gt;
* \t	Horizontal Tab&lt;br /&gt;
* \v	Vertical Tab&lt;br /&gt;
* \b	Backspace&lt;br /&gt;
* \r	Carriage Return&lt;br /&gt;
* \f	Form feed&lt;br /&gt;
* \a	Audible Alert (bell)&lt;br /&gt;
* \\	Backslash&lt;br /&gt;
* \?	Question mark&lt;br /&gt;
* \'	Single quote&lt;br /&gt;
* \&amp;quot;	Double quote&lt;br /&gt;
&lt;br /&gt;
For example, to print a new line, use:&lt;br /&gt;
&lt;br /&gt;
 print (&amp;quot;\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
To print a quoted string, use:&lt;br /&gt;
&lt;br /&gt;
 print (&amp;quot;\&amp;quot;quoted string\&amp;quot;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
and so on.&lt;br /&gt;
&lt;br /&gt;
Single quotes treat everything as literal except for embedded single quotes (including embedded whitespace like newlines).&lt;br /&gt;
&lt;br /&gt;
Nasal strings are always arrays of bytes (never characters: see the utf8 library if you want character-based equivalents of substr() et. al.). They can be indexed just like in C (although note that there is no nul termination -- get the length with size()):&lt;br /&gt;
&lt;br /&gt;
== Editing code files ==&lt;br /&gt;
&lt;br /&gt;
Note that there is currently no way to tell FlightGear to reload Nasal scripts from the global Nasal directory at runtime, so in order to see changes take effect, you will have to exit and restart FlightGear for the time being. Note that there are some workarounds available, see: [[Nasal_scripting_language#Loading.2Freloading_Nasal_code_without_re-starting_Flightgear|reloading Nasal code without re-starting FlightGear]].&lt;br /&gt;
&lt;br /&gt;
Also, note that as of 05/2009, Nasal in FlightGear does not yet support any form of dependency resolution. In other words, there's no &amp;quot;import&amp;quot;, &amp;quot;require&amp;quot; or &amp;quot;include&amp;quot; directive - this is also why most code in FlightGear is wrapped inside a _setlistener() call instead, which in turn waits for a FlightGear signal before executing the code (see below for details).&lt;br /&gt;
&lt;br /&gt;
== Variables ==&lt;br /&gt;
Nasal scripts should make use of the var keyword when declaring variables. The &amp;quot;var&amp;quot; keyword makes a variable guaranteed to be local. Nasal, natively provides support for scalars (numbers, strings), lists (arrays, vectors) and hashes (objects or dictionaries), more complex data structures (such as trees) can be built using vectors or hashes.&lt;br /&gt;
&lt;br /&gt;
 var w=100;     # w is a local numerical variable&lt;br /&gt;
 var x=&amp;quot;hello&amp;quot;; # x is a local string variable&lt;br /&gt;
 var y=[];      # y is a local vector (array)&lt;br /&gt;
 var z={};      # z is a local hash (dictionary or table) - also used for OOP&lt;br /&gt;
&lt;br /&gt;
Nasal supports a &amp;quot;nil&amp;quot; value for use as a null pointer equivalent:&lt;br /&gt;
&lt;br /&gt;
 var foo=nil; &lt;br /&gt;
&lt;br /&gt;
Also, note that Nasal symbols are case-sensitive, these are all different variables:&lt;br /&gt;
&lt;br /&gt;
 var show = func(what) {print(what,&amp;quot;\n&amp;quot;);}&lt;br /&gt;
 var abc=1; # these are all different symbols&lt;br /&gt;
 var ABC=2; # different from abc &lt;br /&gt;
 var aBc=3; # different from abc and ABC&lt;br /&gt;
 &lt;br /&gt;
 show(abc);&lt;br /&gt;
 show(ABC);&lt;br /&gt;
 show(aBc);&lt;br /&gt;
&lt;br /&gt;
Please note that functions assigned to variables are no exception. If you write code without using &amp;quot;var&amp;quot; on variables, then you risk (often hard to debug) breakage at a later time because you may be overwriting symbols in another namespace. &lt;br /&gt;
&lt;br /&gt;
So functions bound to variables should use the &amp;quot;var&amp;quot; keyword as well:&lt;br /&gt;
&lt;br /&gt;
 var hello = func { &lt;br /&gt;
   print(&amp;quot;hello\n&amp;quot;); &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
But there's another reason why &amp;quot;var&amp;quot; should be used consequently, even if a variable is safe enough from later side effects, because it has a relatively specific or unique name: The &amp;quot;var&amp;quot; keyword makes&lt;br /&gt;
reading code for others (and for the author after some time) easier, as it makes clear: &amp;quot;this variable starts its life *HERE*&amp;quot;. No need to search around to see whether assigning a value to it means something to other code outside or not. Also, with an editor offering proper syntax highlighting reading such code is actually easier, despite the &amp;quot;noise&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The problem with nasal code that does not make use of the var keyword is, that it can break other code, and with it the whole system, but no Nasal error message will point you there, as it's syntactically and semantically correct code. Just doing things that it wasn't supposed to do.&lt;br /&gt;
For a more in-depth discussion, please see [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg13557.html].&lt;br /&gt;
&lt;br /&gt;
Also, Nasal scripts that are loaded from $FG_ROOT/Nasal are automatically placed inside a namespace that is based on the script's name.&lt;br /&gt;
&lt;br /&gt;
For example, referring to our earlier &amp;quot;Hello World&amp;quot; example, global variables defined in the hello.nas script would be accessible by using &amp;quot;hello&amp;quot; as prefix from other modules:&lt;br /&gt;
&lt;br /&gt;
 # hello.nas&lt;br /&gt;
 var greeting=&amp;quot;Hello World&amp;quot;; # define a greeting symbol inside the hello namespace&lt;br /&gt;
&lt;br /&gt;
If you were now to read out the value from the greeting variable from another Nasal module, you would have to use the hello prefix:&lt;br /&gt;
&lt;br /&gt;
 # greetme.nas&lt;br /&gt;
 print(hello.greeting); # the hello prefix is referring to the hello namespace (or module).&lt;br /&gt;
&lt;br /&gt;
==Namespaces==&lt;br /&gt;
The Nasal Console built into FlightGear is quite handy when it comes to debugging code. However, here the namespaces need to be considered. In addition, Nasal sub modules (see above) have some special rules, too - basically, all Nasal files part of a &amp;quot;sub module&amp;quot; share a single name space based on the folder's name rather than the name of the individual Nasal files.&lt;br /&gt;
&lt;br /&gt;
For cases of Nasal code specific for an aircraft (like instruments, for example), the corresponding scripts could be loaded through the aircraft's &amp;lt;tt&amp;gt;-set.xml&amp;lt;/tt&amp;gt; file by putting it into the &amp;lt;tt&amp;gt;&amp;lt;nasal&amp;gt;...&amp;lt;/nasal&amp;gt;&amp;lt;tt&amp;gt; section&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;nasal&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;moduleA&amp;gt;&lt;br /&gt;
      &amp;lt;file&amp;gt;path/to/file1.nas&amp;lt;/file&amp;gt;&lt;br /&gt;
      &amp;lt;file&amp;gt;path/to/file2.nas&amp;lt;/file&amp;gt;		&lt;br /&gt;
    &amp;lt;/moduleA&amp;gt;&lt;br /&gt;
    &amp;lt;moduleB&amp;gt;&lt;br /&gt;
      &amp;lt;file&amp;gt;path/to/file3.nas&amp;lt;/file&amp;gt;	&lt;br /&gt;
    &amp;lt;/moduleB&amp;gt;&lt;br /&gt;
  &amp;lt;/nasal&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, variables in files &amp;lt;tt&amp;gt;path/to/file1.nas&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;path/to/file2.nas&amp;lt;/tt&amp;gt; can be used in the Nasal console as&lt;br /&gt;
&lt;br /&gt;
  moduleA.varName;&lt;br /&gt;
&lt;br /&gt;
Variables in &amp;lt;tt&amp;gt;path/to/file3.nas&amp;lt;/tt&amp;gt; can be accessed as&lt;br /&gt;
&lt;br /&gt;
  moduleB.varName;&lt;br /&gt;
&lt;br /&gt;
Please note that Nasal sub modules (i.e. files loaded and run from their own Nasal sub directory), are subject to some special rules, as all Nasal source files are automatically loaded into the same namespace, which is by default based on the sub module's folder name.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''More information can be found by clicking [http://wiki.flightgear.org/Namespaces_and_Methods here].'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Variables - Advanced Uses ==&lt;br /&gt;
&lt;br /&gt;
Nasal, also supports Multi-assignment expressions. You can assign more than one variable (or lvalue) at a time by putting them in a parenthesized list:&lt;br /&gt;
&lt;br /&gt;
   (var a, var b) = (1, 2);&lt;br /&gt;
   var (a, b) = (1, 2);               # Shorthand for (var a, var b)&lt;br /&gt;
   (var a, v[0], obj.field) = (1,2,3) # Any assignable lvalue works&lt;br /&gt;
   var color = [1, 1, 0.5];&lt;br /&gt;
   var (r, g, b) = color;  # works with runtime vectors too&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Vectors (lists or arrays) can be created from others using an ordered list of indexes and ranges. &lt;br /&gt;
This is usually called &amp;quot;vector slicing&amp;quot;.&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
   var v1 = [&amp;quot;a&amp;quot;,&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;,&amp;quot;d&amp;quot;,&amp;quot;e&amp;quot;]&lt;br /&gt;
   # &lt;br /&gt;
   var v2 = v1[3,2];   # == [&amp;quot;d&amp;quot;,&amp;quot;c&amp;quot;];&lt;br /&gt;
   var v3 = v1[1:3];   # i.e. range from 1 to 3: [&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;,&amp;quot;d&amp;quot;];&lt;br /&gt;
   var v4 = v1[1:];    # no value means &amp;quot;to the end&amp;quot;: [&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;,&amp;quot;d&amp;quot;,&amp;quot;e&amp;quot;]&lt;br /&gt;
   var i = 2;&lt;br /&gt;
   var v5 = v1[i];     # runtime expressions are fine: [&amp;quot;c&amp;quot;]&lt;br /&gt;
   var v6 = v1[-2,-1]; # negative indexes are relative to end: [&amp;quot;d&amp;quot;,&amp;quot;e&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
The range values can be computed at runtime (e.g. i=1; v5=v1[i:]). Negative indices work the same way they do with the vector functions (-1 is the last element, -2 is 2nd to last, etc...).&lt;br /&gt;
&lt;br /&gt;
== Storage: property tree vs. Nasal ==&lt;br /&gt;
With FlightGear's built-in property tree and Nasal's support for it, there are two obvious, and two somewhat competing, ways for storing scalar data: native Nasal variables and FlightGear properties, both of which can be easily accessed and managed from Nasal.&lt;br /&gt;
&lt;br /&gt;
The advantage to native Nasal-space data is that it's fast and simple.  If the only thing that will care about the value is your script, they are good choices.&lt;br /&gt;
&lt;br /&gt;
The property tree is an inter-subsystem communication thing.  This is what you want if you want to share data with the C++ world (for example, YASim &amp;lt;control-output&amp;gt; tags write to properties -- they don't understand Nasal), or read in via configuration files.&lt;br /&gt;
&lt;br /&gt;
Also, native Nasal data structures are usually far faster than their equivalent in property tree space.  This is because there are several layers of indirection in retrieving a property tree value. &lt;br /&gt;
&lt;br /&gt;
In general, this means that you shouldn't make overly excessive use of the property tree for storing state that isn't otherwise relevant to FlightGear or any of its subsystems. Doing that would in fact have adverse effects on the performance of your code. In general, you should favor Nasal variables and data structures and should only make use of properties to interface with the rest of FlightGear, or to easily provide debugging information at run time.&lt;br /&gt;
&lt;br /&gt;
As of FG 2.4.0, retrieving a value from the property tree via getprop is about 50% slower than accessing a native Nasal variable, and accessing the value via node.getValue() is 10-20% slower yet. This is an insignificant amount of time if you are retrieving and storing a few individual values from the property tree, but adds up fast if you are storing or retrieving hashes or large amounts of data.  (You can easily benchmark times on your own code using systime() or debug.benchmark.)&lt;br /&gt;
&lt;br /&gt;
In addition, it is worth noting that the Nasal/FlightGear APIs cannot currently be considered to be thread safe, this mean that -at least for now- the explicit use of pure Nasal space variables is the only way to exploit possible parallelism in your code by making use of threads.&lt;br /&gt;
&lt;br /&gt;
== Functions ==&lt;br /&gt;
&lt;br /&gt;
=== What is a function ? ===&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;function&amp;quot; is a piece of code that can be easily used repeatedly (without repeating the same code over and over again), this is achieved by associating a symbolic name with the piece of code, such as &amp;quot;print&amp;quot;, &amp;quot;show&amp;quot; or &amp;quot;get&amp;quot; for example. Whenever this symbolic name is then used in the program, the program will &amp;quot;jump&amp;quot; to the definition of the function and start running it, once the called function has completed it will automatically return to the instruction following the call.&lt;br /&gt;
&lt;br /&gt;
By using so called &amp;quot;function arguments&amp;quot; (see below) it is possible to parametrize a function (using variables) so that it may use data that is specific to each invocation.&lt;br /&gt;
&lt;br /&gt;
As previously shown, Nasal functions are implemented using the func keyword, The following snippet of code defines a new function named &amp;quot;log_message&amp;quot; with an empty function body (the curly braces).&lt;br /&gt;
&lt;br /&gt;
 var log_message = func {}&lt;br /&gt;
&lt;br /&gt;
=== Function bodies ===&lt;br /&gt;
&lt;br /&gt;
To add a function body, you need to add code in between these curly braces.&lt;br /&gt;
&lt;br /&gt;
=== Anonymous function arguments ===&lt;br /&gt;
&lt;br /&gt;
In Nasal, arguments are by default passed in the &amp;quot;arg&amp;quot; array, not unlike perl. To understand how this works, you should probably first read up on Nasal vectors.&lt;br /&gt;
&lt;br /&gt;
 var log_message = func {&lt;br /&gt;
    print(arg[0]);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Note that this is equivalent to:&lt;br /&gt;
&lt;br /&gt;
 var log_message = func() {&lt;br /&gt;
    print(arg[0]);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In other words, the argument list &amp;quot;()&amp;quot; can be omitted if it is empty.&lt;br /&gt;
However, if you are new to Nasal or programming in general, it is probably a good idea to ALWAYS use parentheses, i.e. also for functions with empty argument lists - that makes it easy to get used to the syntax.&lt;br /&gt;
&lt;br /&gt;
Note that this is just an assignment of an (anonymous) function argument to the local &amp;quot;log_message&amp;quot; variable. There is no function declaration syntax in Nasal.&lt;br /&gt;
&lt;br /&gt;
Also, Nasal being a functional programming language, all passed arguments will be local to the corresponding scope. If you want to modify state in a function, you'll preferably return new state to the caller.&lt;br /&gt;
&lt;br /&gt;
===Named function arguments===&lt;br /&gt;
You can also pass named arguments to a function, thus saving the typing and performance costs of extracting them from the arg array:&lt;br /&gt;
&lt;br /&gt;
 var log_message = func(msg) {&lt;br /&gt;
    print(msg);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The list of function arguments is called a function's &amp;quot;signature&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Default values for function arguments ===&lt;br /&gt;
&lt;br /&gt;
Function arguments can have default values, as in C++. Note that the default value must be a scalar (number, string, function, nil) and not a mutable composite object (list, hash).&lt;br /&gt;
&lt;br /&gt;
 var log_message = func(msg=&amp;quot;error&amp;quot;) {&lt;br /&gt;
    print(msg);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If some arguments have default values and some do not, those with default values must come first in the argument list:&lt;br /&gt;
&lt;br /&gt;
 #Incorrect:&lt;br /&gt;
 var log_message = func(msg=&amp;quot;error&amp;quot;, line, object=&amp;quot;ground&amp;quot;) { #some code }&lt;br /&gt;
&lt;br /&gt;
 #Correct:&lt;br /&gt;
 var log_message = func(msg=&amp;quot;error&amp;quot;, object=&amp;quot;ground&amp;quot;, line) { #some code }&lt;br /&gt;
&lt;br /&gt;
Any extra arguments after the named list are placed in the &amp;quot;arg&amp;quot; vector as above. You can rename this to something other than &amp;quot;arg&amp;quot; by specifying a final argument name with an ellipsis:&lt;br /&gt;
&lt;br /&gt;
 listify = func(elements...) { return elements; }&lt;br /&gt;
 listify(1, 2, 3, 4); # returns a list: [1, 2, 3, 4]&lt;br /&gt;
&lt;br /&gt;
=== Returning from functions ===&lt;br /&gt;
&lt;br /&gt;
In Nasal, functions return implicitly the values of the last expression (i.e. &amp;quot;nil&amp;quot; in empty function bodies), you can also add an explicit &amp;quot;return&amp;quot; statement, for example to leave a function early. In addition, it is possible to return values, too.&lt;br /&gt;
&lt;br /&gt;
So, semantically, the previous snippet of code is equivalent to these:&lt;br /&gt;
&lt;br /&gt;
 var log_message = func {return;}&lt;br /&gt;
&lt;br /&gt;
 var log_message = func {nil;}&lt;br /&gt;
&lt;br /&gt;
 var log_message = func {}; &lt;br /&gt;
&lt;br /&gt;
 var log_message = func return;&lt;br /&gt;
&lt;br /&gt;
 var log_message = func nil;&lt;br /&gt;
&lt;br /&gt;
===Named arguments in function calls===&lt;br /&gt;
Nasal supports named function arguments in function calls, too.&lt;br /&gt;
&lt;br /&gt;
As an alternative to the comma-separated list of ''positional'' function arguments, you can specify a hash literal in place of ordered function arguments, and it will become the local variable namespace for the called function, with variables named according to the hash indexes and with values according to the hash values.  This makes functions with many arguments more readable. &lt;br /&gt;
&lt;br /&gt;
And it also makes it possible to call function's without having to take care of the right order of passing arguments.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
 #if we have functions defined:&lt;br /&gt;
 var log_message = func (msg=&amp;quot;&amp;quot;) { #some code to log variable msg }&lt;br /&gt;
 var lookat =  func (heading=0, pitch=0, roll=0, x=nil, y=nil, z=nil, time=hil, fov=20) { #some code using those variables }&lt;br /&gt;
&lt;br /&gt;
 #we can use them them the usual way with comma separated list of arguments:&lt;br /&gt;
 log_message(&amp;quot;Hello World!&amp;quot;);&lt;br /&gt;
 lookat (180, 20, 0, XO, YO, ZO, now, 55);&lt;br /&gt;
&lt;br /&gt;
 #or we can use the hash literal arguments instead:&lt;br /&gt;
 log_message(msg:&amp;quot;Hello World!&amp;quot;);&lt;br /&gt;
 lookat(heading:180, pitch:20, roll:0, x:X0, y:Y0, z:Z0,time:now, fov:55);&lt;br /&gt;
&lt;br /&gt;
Both methods for calling the functions above are equivalent, but note the the second method is more readable, less prone to error, and self-documenting in the code for the function call.&lt;br /&gt;
&lt;br /&gt;
As another example, consider:&lt;br /&gt;
&lt;br /&gt;
 var setPosition = func (latitude_deg, longitude_deg, altitude_ft) {&lt;br /&gt;
  # do something here &lt;br /&gt;
 }&lt;br /&gt;
 # the actual function call:&lt;br /&gt;
 setPosition( latitude_deg:34.00, longitude_deg:7.00, alt_ft:10000);&lt;br /&gt;
&lt;br /&gt;
In other words, such function calls become much more self-explanatory because everybody can see immediately what a value is doing.&lt;br /&gt;
This is a good practice, as you may eventually have to take a longer break, away from your code - and then even you yourself will come to appreciate such small things that make code more intuitive to work with.&lt;br /&gt;
&lt;br /&gt;
Declared arguments are checked and defaulted as would be expected: it's an error if you fail to pass a value for an undefaulted argument, missing default arguments get assigned as usual, and any rest parameter (e.g. &amp;quot;func(a,b=2,rest...){}&amp;quot;) will be assigned with an empty vector.&lt;br /&gt;
&lt;br /&gt;
===Nested functions, implicit return ===&lt;br /&gt;
Also, Nasal functions can be easily nested, for example:&lt;br /&gt;
&lt;br /&gt;
  var calculate = func(param1,param2,operator) {&lt;br /&gt;
   var add = func(p1,p2) {p1+p2;}&lt;br /&gt;
   var sub = func(p1,p2) {p1-p2;}&lt;br /&gt;
   var mul = func(p1,p2) {p1*p2;}&lt;br /&gt;
   var div = func(p1,p2) {p1/p2;}&lt;br /&gt;
   if (operator==&amp;quot;+&amp;quot;) return add(param1,param2);&lt;br /&gt;
   if (operator==&amp;quot;-&amp;quot;) return sub(param1,param2);&lt;br /&gt;
   if (operator==&amp;quot;*&amp;quot;) return mul(param1,param2);&lt;br /&gt;
   if (operator==&amp;quot;/&amp;quot;) return div(param1,param2);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Note that the add,sub,mul and div functions in this example do not make use of an explicit return statement, instead the result of each expression is implicitly returned to the caller.&lt;br /&gt;
&lt;br /&gt;
Nasal functions that just consist of such simple expressions can also be further simplified to read:&lt;br /&gt;
&lt;br /&gt;
  var add = func(val1,val2) val1+val2;&lt;br /&gt;
&lt;br /&gt;
=== Function overloading ===&lt;br /&gt;
&lt;br /&gt;
Note that Nasal functions can generally not be [[http://en.wikipedia.org/wiki/Function_overloading overloaded]], and that operator overloading in particular is also not supported.&lt;br /&gt;
&lt;br /&gt;
However, the effects of '''function overloading''' can obviously be implemented individually by each function, simply by processing the number and type of passed arguments at the start of the function body. The FlightGear code base contains a number of examples for this, i.e. it is for example possible to pass properties in the form of plain strings to a callback or in the form of a Nasal wrapper like props.Node.&lt;br /&gt;
&lt;br /&gt;
So this can be accomplished by first checking the argument count and then the types of arguments passed to the function.&lt;br /&gt;
&lt;br /&gt;
To provide an example, here's a simple function to multiply two numbers, no matter if they are provided as scalars, as a vector or as x/y members of a hash:&lt;br /&gt;
&lt;br /&gt;
 var multiply2 = func (params) {&lt;br /&gt;
  if (typeof(params)==&amp;quot;scalar&amp;quot;) return params*arg[0];&lt;br /&gt;
  if (typeof(params)==&amp;quot;vector&amp;quot;) return params[0]*params[1];&lt;br /&gt;
  if (typeof(params)==&amp;quot;hash&amp;quot;)   return params.x*params.y;&lt;br /&gt;
  die(&amp;quot;cannot do what you want me to do&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
So, now you have a very simple form of an &amp;quot;overloaded&amp;quot; function that supports different argument types and numbers:&lt;br /&gt;
&lt;br /&gt;
 multiply2(  2,6); # multiply two scalars&lt;br /&gt;
 multiply2( [5,7] ); # multiply two scalars stored in a vector&lt;br /&gt;
 multiply2( {x:8, y:9} ); # multiply two scalars stored in a hash&lt;br /&gt;
&lt;br /&gt;
You could obviously extend this easily to support an arbitrary number of arguments by just using a for loop here.&lt;br /&gt;
&lt;br /&gt;
As you can see, the basic idea is pretty simple and also scalable, you could easily extend this to and also return different types of values, such as vectors or hashes. This could for example be used to create wrappers in Nasal space for doing 3D maths, with vectors and matrices, so that a matrix multiplication could return a new matrix, too.&lt;br /&gt;
&lt;br /&gt;
===Functional programming, higher order functions, generators;===&lt;br /&gt;
As previously mentioned, arguments to a Nasal function can also be functions themselves (Nasal being a functional programming language), this means that Nasal functions are higher order functions so that you can easily pass and return functions to and from Nasal functions. This can for example be used to dynamically create new functions (such functions are commonly called 'generators'):&lt;br /&gt;
&lt;br /&gt;
  # a function that returns a new custom function&lt;br /&gt;
  var i18n_hello = func(hello) {&lt;br /&gt;
   return func(name) { # returns an anonymous/unnamed function&lt;br /&gt;
     print(hello,name);&lt;br /&gt;
   }&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
  # create three new functions&lt;br /&gt;
  var english_hello = i18n_hello(&amp;quot;Good Day &amp;quot;);&lt;br /&gt;
  var spanish_hello = i18n_hello(&amp;quot;Buenos Dias &amp;quot;);&lt;br /&gt;
  var italian_hello = i18n_hello(&amp;quot;Buon giorno &amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
  # actually call these functions&lt;br /&gt;
  english_hello(&amp;quot;FlightGear&amp;quot;);&lt;br /&gt;
  spanish_hello(&amp;quot;FlightGear&amp;quot;);&lt;br /&gt;
  italian_hello(&amp;quot;FlightGear&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
=== Using helper functions ===&lt;br /&gt;
&lt;br /&gt;
It is possible to simplify complex function calls by introducing small helper functions, for example consider:&lt;br /&gt;
&lt;br /&gt;
 var l = thermalLift.new(ev.lat, ev.lon, ev.radius, ev.height, ev.cn, ev.sh, ev.max_lift, ev.f_lift_radius);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, you could just as well create a small helper function named&amp;quot;thermalLift.new_from_ev(ev)&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
  thermalLift.new_from_ev = func (ev) {&lt;br /&gt;
   thermalLift.new(ev.lat, ev.lon, ev.radius, ev.height, ev.cn, ev.sh, ev.max_lift, ev.f_lift_radius);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 var l=thermalLift.new_from_ev(ev);&lt;br /&gt;
&lt;br /&gt;
Note that the expression to invoke your code would then also become less complicated and much more comprehensible.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you have expressions of nested method calls, such as:&lt;br /&gt;
&lt;br /&gt;
    t.getNode(&amp;quot;latitude-deg&amp;quot;).setValue(f.getNode(&amp;quot;latitude-deg&amp;quot;).getValue());&lt;br /&gt;
    t.getNode(&amp;quot;longitude-deg&amp;quot;).setValue(f.getNode(&amp;quot;longitude-deg&amp;quot;).getValue());&lt;br /&gt;
&lt;br /&gt;
You could just as easily introduce a small helper function to wrap the code, that would be less typing for you, less code to read (and understand) for others and generally it would help localize functionality (and possible errors):&lt;br /&gt;
&lt;br /&gt;
    var copyNode = func(t,f,path) t.getNode(path).setValue(f.getNode(path).getValue());&lt;br /&gt;
&lt;br /&gt;
So you would simply take the complex expression and generalize it by adding variables that you pass in from a function object, then you could simply call your new function like this:&lt;br /&gt;
&lt;br /&gt;
    copyNode(t,f,&amp;quot;latitude-deg&amp;quot;);&lt;br /&gt;
    copyNode(t,f,&amp;quot;longitude-deg&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
    foreach(var p; [&amp;quot;latitude-deg&amp;quot;, &amp;quot;longitude-deg&amp;quot;,&amp;quot;generated-flag&amp;quot;])&lt;br /&gt;
      copyNode(t,f,p);&lt;br /&gt;
&lt;br /&gt;
or as a complete function accepting a vector of properties:&lt;br /&gt;
&lt;br /&gt;
    var copyNode = func(target,source,properties) { &lt;br /&gt;
     if (typeof(properties)!=&amp;quot;vector&amp;quot;) properties=[properties];&lt;br /&gt;
     if (typeof(target)!=&amp;quot;hash&amp;quot;) target=props.globals.getNode(target);&lt;br /&gt;
     if (typeof(source)!=&amp;quot;hash&amp;quot;) target=props.globals.getNode(source)&lt;br /&gt;
     foreach(var path; properties)&lt;br /&gt;
      target.getNode(path).setValue( source.getNode(path).getValue() );&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    copyNode(&amp;quot;/temp/test&amp;quot;, &amp;quot;/position&amp;quot;, [&amp;quot;latitude-deg&amp;quot;, &amp;quot;longitude-deg&amp;quot;, &amp;quot;altitude-ft&amp;quot;]);&lt;br /&gt;
&lt;br /&gt;
Whenever you have very similar lines of code that seem fairly repetitive, it is a good idea to consider introducing small helper functions. You can use plenty of small helper functions and then just &amp;quot;chain&amp;quot; them together, rather than using complex nested expressions that make your head spin.&lt;br /&gt;
&lt;br /&gt;
== Conditionals ==&lt;br /&gt;
&lt;br /&gt;
Nasal has no &amp;quot;statements&amp;quot;, which means that any expression can appear in any context. This means that you can use an if/else clause to do what the ?: does in C. &lt;br /&gt;
The last semicolon in a code block is optional, to make this prettier&lt;br /&gt;
&lt;br /&gt;
 abs = func(n) { if(n&amp;lt;0) { -n } else { n } }&lt;br /&gt;
&lt;br /&gt;
But for those who don't like typing, the ternary operator works like you expect:&lt;br /&gt;
&lt;br /&gt;
 abs = func(n) { n &amp;lt; 0 ? -n : n }&lt;br /&gt;
&lt;br /&gt;
In addition, Nasal supports braceless blocks, like they're known from C/C++ and other languages:&lt;br /&gt;
&lt;br /&gt;
 var foo=1;&lt;br /&gt;
 if (foo)&lt;br /&gt;
   print(&amp;quot;1\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
   print(&amp;quot;0\n&amp;quot;);&lt;br /&gt;
 print(&amp;quot;this is printed regardless\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Instead of a switch statement one can use&lt;br /&gt;
&lt;br /&gt;
  if (1==2) {&lt;br /&gt;
    print(&amp;quot;wrong&amp;quot;);&lt;br /&gt;
  } else if (1==3) { # NOTE the space between else and if&lt;br /&gt;
    print(&amp;quot;wronger&amp;quot;);&lt;br /&gt;
  } else {&lt;br /&gt;
    print(&amp;quot;don't know&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
which produces the expected output of &amp;lt;code&amp;gt;don't know&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;nil&amp;lt;/tt&amp;gt; logic is actually quite logical, let's just restate the obvious:&lt;br /&gt;
&lt;br /&gt;
  if (nil) {&lt;br /&gt;
    print(&amp;quot;This should never be printed&amp;quot;);&lt;br /&gt;
  } else {&lt;br /&gt;
    print(&amp;quot;This will be printed, because nil is always false&amp;quot;);		&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nasal's binary boolean operators are &amp;quot;and&amp;quot; and &amp;quot;or&amp;quot;, unlike C. unary not is still &amp;quot;!&amp;quot; however. &lt;br /&gt;
They short-circuit like you expect&lt;br /&gt;
&lt;br /&gt;
 var toggle = 0;&lt;br /&gt;
 var a = nil;&lt;br /&gt;
 if(a and a.field == 42) {&lt;br /&gt;
    toggle = !toggle; # doesn't crash when a is nil&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
You can easily reduce the complexity of huge conditional (IF) statements, such as this one:&lt;br /&gt;
&lt;br /&gt;
    if (a==1) function_a();&lt;br /&gt;
    else&lt;br /&gt;
    if (a==2) function_b();&lt;br /&gt;
    else&lt;br /&gt;
    if (a==3) function_c();&lt;br /&gt;
    else&lt;br /&gt;
    if (a==4) function_d();&lt;br /&gt;
    else&lt;br /&gt;
    if (a==5) function_e();&lt;br /&gt;
&lt;br /&gt;
.. just by using the variable as a key (index) into a hash, so that you can directly call the corresponding function:&lt;br /&gt;
&lt;br /&gt;
    var mapping = {1:function_a, 2:function_b, 3:function_c, 4:function_d,5:function_e};&lt;br /&gt;
    mapping[a] ();&lt;br /&gt;
&lt;br /&gt;
This initializes first a hash map of values and maps a function &amp;quot;pointer&amp;quot; to each value, so that accessing mapping[x] will return the function pointer for the key &amp;quot;x&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Next, you can actually call the function by appending a list of function arguments (empty parentheses for no args) to the hash lookup.&lt;br /&gt;
&lt;br /&gt;
Using this technique, you can reduce the complexity of huge conditional blocks. For example, consider:&lt;br /&gt;
&lt;br /&gt;
    # weather_tile_management.nas&lt;br /&gt;
    460         if (code == &amp;quot;altocumulus_sky&amp;quot;){weather_tiles.set_altocumulus_tile();}&lt;br /&gt;
    461         else if (code == &amp;quot;broken_layers&amp;quot;) {weather_tiles.set_broken_layers_tile();}&lt;br /&gt;
    462         else if (code == &amp;quot;stratus&amp;quot;) {weather_tiles.set_overcast_stratus_tile();}&lt;br /&gt;
    463         else if (code == &amp;quot;cumulus_sky&amp;quot;) {weather_tiles.set_fair_weather_tile();}&lt;br /&gt;
    464         else if (code == &amp;quot;gliders_sky&amp;quot;) {weather_tiles.set_gliders_sky_tile();}&lt;br /&gt;
    465         else if (code == &amp;quot;blue_thermals&amp;quot;) {weather_tiles.set_blue_thermals_tile();}&lt;br /&gt;
    466         else if (code == &amp;quot;summer_rain&amp;quot;) {weather_tiles.set_summer_rain_tile();}&lt;br /&gt;
    467         else if (code == &amp;quot;high_pressure_core&amp;quot;) {weather_tiles.set_high_pressure_core_tile();}&lt;br /&gt;
    468         else if (code == &amp;quot;high_pressure&amp;quot;) {weather_tiles.set_high_pressure_tile();}&lt;br /&gt;
    469         else if (code == &amp;quot;high_pressure_border&amp;quot;) {weather_tiles.set_high_pressure_border_tile();}&lt;br /&gt;
    470         else if (code == &amp;quot;low_pressure_border&amp;quot;) {weather_tiles.set_low_pressure_border_tile();}&lt;br /&gt;
    471         else if (code == &amp;quot;low_pressure&amp;quot;) {weather_tiles.set_low_pressure_tile();}&lt;br /&gt;
    472         else if (code == &amp;quot;low_pressure_core&amp;quot;) {weather_tiles.set_low_pressure_core_tile();}&lt;br /&gt;
    473         else if (code == &amp;quot;cold_sector&amp;quot;) {weather_tiles.set_cold_sector_tile();}&lt;br /&gt;
    474         else if (code == &amp;quot;warm_sector&amp;quot;) {weather_tiles.set_warm_sector_tile();}&lt;br /&gt;
    475         else if (code == &amp;quot;tropical_weather&amp;quot;) {weather_tiles.set_tropical_weather_tile();}&lt;br /&gt;
    476         else if (code == &amp;quot;test&amp;quot;) {weather_tiles.set_4_8_stratus_tile();}&lt;br /&gt;
    477         else ...&lt;br /&gt;
&lt;br /&gt;
While this is not a very complex or huge block of code, it is an excellent example for very good naming conventions used already, because the consistency of naming variables and functions can pay off easily here, with just some very small changes, you can already reduce the whole thing to a hash lookup like this:&lt;br /&gt;
&lt;br /&gt;
  weather_tiles[&amp;quot;set_&amp;quot;~code~&amp;quot;_tile&amp;quot;]();  # naming convention&lt;br /&gt;
&lt;br /&gt;
This would dynamically concatenate a key consisting of &amp;quot;set_&amp;quot; + code + &amp;quot;_title&amp;quot; into the hash named weather_tiles, and then call the function that is returned from the hash lookup.&lt;br /&gt;
&lt;br /&gt;
So for this to work you only need to enforce consistency when naming your functions (i.e. this would of course CURRENTLY fail when the variable code contains &amp;quot;test&amp;quot; because there is no such hash member (it's &amp;quot;4_8_stratus&amp;quot; instead).&lt;br /&gt;
&lt;br /&gt;
The same applies to cumulus sky (fair weather), stratus/overcast stratus.&lt;br /&gt;
&lt;br /&gt;
But these are very simple changes to do (just renaming these functions to match the existing conventions). When you do that, you can easily replace such huge IF statements and replace them with a single hash lookup and function call:&lt;br /&gt;
&lt;br /&gt;
 hash[key] (arguments...);&lt;br /&gt;
&lt;br /&gt;
For example, consider:&lt;br /&gt;
&lt;br /&gt;
 var makeFuncString = func(c) return tolower(&amp;quot;set_&amp;quot;~c~&amp;quot;_tile&amp;quot;);&lt;br /&gt;
 var isFunc = func(f) typeof(f)=='func';&lt;br /&gt;
 var hasMethod = func(h,m) contains(h,m) and isFunc;&lt;br /&gt;
 var callIfAvailable = func(hash, method, unavailable=func{} ) {&lt;br /&gt;
  var c=hasMethod(hash,makeFuncString(m) ) or unavailable();&lt;br /&gt;
  hash[makeFuncString(m)] ();&lt;br /&gt;
 }&lt;br /&gt;
 callIfAvailable( weather_tiles,code, func {die(&amp;quot;key not found in hash or not a func&amp;quot;);} );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Initializing data structures ==&lt;br /&gt;
&lt;br /&gt;
There are some more possibilities to increase the density of your code, such as by removing redundant code or by generalizing and refactoring existing code so that it can be reused in different places (i.e. avoiding duplicate code): &lt;br /&gt;
&lt;br /&gt;
For example see weather_tile_management.nas #1000 (create_neighbours function):&lt;br /&gt;
&lt;br /&gt;
    1008 x = -40000.0; y = 40000.0;&lt;br /&gt;
    1009 setprop(lw~&amp;quot;tiles/tile[0]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1010 setprop(lw~&amp;quot;tiles/tile[0]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1011 setprop(lw~&amp;quot;tiles/tile[0]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1012 setprop(lw~&amp;quot;tiles/tile[0]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1013 setprop(lw~&amp;quot;tiles/tile[0]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1014 setprop(lw~&amp;quot;tiles/tile[0]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1015 setprop(lw~&amp;quot;tiles/tile[0]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1016&lt;br /&gt;
    1017 x = 0.0; y = 40000.0;&lt;br /&gt;
    1018 setprop(lw~&amp;quot;tiles/tile[1]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1019 setprop(lw~&amp;quot;tiles/tile[1]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1020 setprop(lw~&amp;quot;tiles/tile[1]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1021 setprop(lw~&amp;quot;tiles/tile[1]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1022 setprop(lw~&amp;quot;tiles/tile[1]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1023 setprop(lw~&amp;quot;tiles/tile[1]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1024 setprop(lw~&amp;quot;tiles/tile[1]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1025&lt;br /&gt;
    1026 x = 40000.0; y = 40000.0;&lt;br /&gt;
    1027 setprop(lw~&amp;quot;tiles/tile[2]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1028 setprop(lw~&amp;quot;tiles/tile[2]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1029 setprop(lw~&amp;quot;tiles/tile[2]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1030 setprop(lw~&amp;quot;tiles/tile[2]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1031 setprop(lw~&amp;quot;tiles/tile[2]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1032 setprop(lw~&amp;quot;tiles/tile[2]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1033 setprop(lw~&amp;quot;tiles/tile[2]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1034&lt;br /&gt;
    1035 x = -40000.0; y = 0.0;&lt;br /&gt;
    1036 setprop(lw~&amp;quot;tiles/tile[3]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1037 setprop(lw~&amp;quot;tiles/tile[3]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1038 setprop(lw~&amp;quot;tiles/tile[3]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1039 setprop(lw~&amp;quot;tiles/tile[3]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1040 setprop(lw~&amp;quot;tiles/tile[3]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1041 setprop(lw~&amp;quot;tiles/tile[3]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1042 setprop(lw~&amp;quot;tiles/tile[3]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1043&lt;br /&gt;
    1044 # this is the current tile&lt;br /&gt;
    1045 x = 0.0; y = 0.0;&lt;br /&gt;
    1046 setprop(lw~&amp;quot;tiles/tile[4]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1047 setprop(lw~&amp;quot;tiles/tile[4]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1048 setprop(lw~&amp;quot;tiles/tile[4]/generated-flag&amp;quot;,1);&lt;br /&gt;
    1049 setprop(lw~&amp;quot;tiles/tile[4]/tile-index&amp;quot;,1);&lt;br /&gt;
    1050 setprop(lw~&amp;quot;tiles/tile[4]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1051 setprop(lw~&amp;quot;tiles/tile[4]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1052 setprop(lw~&amp;quot;tiles/tile[4]/orientation-deg&amp;quot;,getprop(lw~&amp;quot;tmp/tile-orientation-deg&amp;quot;));&lt;br /&gt;
    1053&lt;br /&gt;
    1054&lt;br /&gt;
    1055 x = 40000.0; y = 0.0;&lt;br /&gt;
    1056 setprop(lw~&amp;quot;tiles/tile[5]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1057 setprop(lw~&amp;quot;tiles/tile[5]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1058 setprop(lw~&amp;quot;tiles/tile[5]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1059 setprop(lw~&amp;quot;tiles/tile[5]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1060 setprop(lw~&amp;quot;tiles/tile[5]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1061 setprop(lw~&amp;quot;tiles/tile[5]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1062 setprop(lw~&amp;quot;tiles/tile[5]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1063&lt;br /&gt;
    1064 x = -40000.0; y = -40000.0;&lt;br /&gt;
    1065 setprop(lw~&amp;quot;tiles/tile[6]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1066 setprop(lw~&amp;quot;tiles/tile[6]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1067 setprop(lw~&amp;quot;tiles/tile[6]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1068 setprop(lw~&amp;quot;tiles/tile[6]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1069 setprop(lw~&amp;quot;tiles/tile[6]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1070 setprop(lw~&amp;quot;tiles/tile[6]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1071 setprop(lw~&amp;quot;tiles/tile[6]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1072&lt;br /&gt;
    1073 x = 0.0; y = -40000.0;&lt;br /&gt;
    1074 setprop(lw~&amp;quot;tiles/tile[7]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1075 setprop(lw~&amp;quot;tiles/tile[7]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1076 setprop(lw~&amp;quot;tiles/tile[7]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1077 setprop(lw~&amp;quot;tiles/tile[7]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1078 setprop(lw~&amp;quot;tiles/tile[7]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1079 setprop(lw~&amp;quot;tiles/tile[7]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1080 setprop(lw~&amp;quot;tiles/tile[7]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1081&lt;br /&gt;
    1082 x = 40000.0; y = -40000.0;&lt;br /&gt;
    1083 setprop(lw~&amp;quot;tiles/tile[8]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    1084 setprop(lw~&amp;quot;tiles/tile[8]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    1085 setprop(lw~&amp;quot;tiles/tile[8]/generated-flag&amp;quot;,0);&lt;br /&gt;
    1086 setprop(lw~&amp;quot;tiles/tile[8]/tile-index&amp;quot;,-1);&lt;br /&gt;
    1087 setprop(lw~&amp;quot;tiles/tile[8]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    1088 setprop(lw~&amp;quot;tiles/tile[8]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    1089 setprop(lw~&amp;quot;tiles/tile[8]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    1090 }&lt;br /&gt;
&lt;br /&gt;
At first glance, this seems like a fairly repetitive and redundant block of code, so it could probably be simplified easily:&lt;br /&gt;
&lt;br /&gt;
    var create_neighbours = func (blat, blon, alpha)        {&lt;br /&gt;
    var phi = alpha * math.pi/180.0;&lt;br /&gt;
    calc_geo(blat);&lt;br /&gt;
    var index=0;&lt;br /&gt;
    var pos = [  [-40000.0,40000.0], [0.0, 40.000], [40000.0, 40000.0], [-40000, 0],  [0,0], [40000,0], [-40000,-40000], [0,-40000], [40000,-40000] ];&lt;br /&gt;
    foreach (var p;pos) {&lt;br /&gt;
    x=p[0]; y=p[1];&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/latitude-deg&amp;quot;,blat + get_lat(x,y,phi));&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/longitude-deg&amp;quot;,blon + get_lon(x,y,phi));&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/generated-flag&amp;quot;,0);&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/tile-index&amp;quot;,-1);&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/code&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/timestamp-sec&amp;quot;,weather_dynamics.time_lw);&lt;br /&gt;
    setprop(lw~&amp;quot;tiles/tile[index]/orientation-deg&amp;quot;,alpha);&lt;br /&gt;
    index=index+1;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
&lt;br /&gt;
Nasal has several ways to implement an iteration.&lt;br /&gt;
&lt;br /&gt;
===for, while, foreach, and forindex loops===&lt;br /&gt;
Nasal's looping constructs are mostly C-like:&lt;br /&gt;
&lt;br /&gt;
 for(var i=0; i &amp;lt; 3; i = i+1) {&lt;br /&gt;
  # loop body&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
 while (condition) {&lt;br /&gt;
 # loop body&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The differences are that there is no do{}while(); construct, and there is a foreach, which takes a local variable name as its first argument and a vector as its second:&lt;br /&gt;
&lt;br /&gt;
  foreach(elem; list1) { doSomething(elem); }  # NOTE: the delimiter is a SEMICOLON ;&lt;br /&gt;
&lt;br /&gt;
The hash/vector index expression is an lvalue that can be assigned as well as inspected:&lt;br /&gt;
&lt;br /&gt;
  foreach(light; lights) { lightNodes[light] = propertyPath; }&lt;br /&gt;
&lt;br /&gt;
To walk through all elements of a hash, for a foreach loop on the keys of they hash.  Then you call pull up the values of the hash using the key.  Example:&lt;br /&gt;
&lt;br /&gt;
 myhash= {first: 1000, second: 250, third: 25.2 };&lt;br /&gt;
 foreach (var i; keys (myhash)) {&lt;br /&gt;
   #multiply each value by 2:&lt;br /&gt;
   myhash[i] *= 2; &lt;br /&gt;
   #print the key and new value:&lt;br /&gt;
   print (i, &amp;quot;: &amp;quot;, myhash[i]);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
There is also a &amp;quot;forindex&amp;quot;, which is like foreach except that it assigns the index of each element, instead of the value, to the loop variable.&lt;br /&gt;
&lt;br /&gt;
 forindex(i; list1) { doSomething(list1[i]); }&lt;br /&gt;
&lt;br /&gt;
Also, braceless blocks work for loops equally well:&lt;br /&gt;
&lt;br /&gt;
 var c=0;&lt;br /&gt;
 while( c&amp;lt;5 )&lt;br /&gt;
  print( c+=1 );&lt;br /&gt;
 print(&amp;quot;end of loop\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
===settimer loops===&lt;br /&gt;
Loops using &amp;lt;tt&amp;gt;while&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;foreach&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;forindex&amp;lt;/tt&amp;gt; block all of FlightGear's subsystems that run in the main thread, and can, thus, only be used for instantaneous operations that don't take too long. &lt;br /&gt;
&lt;br /&gt;
For operations that should continue over a longer period, one needs a non-blocking solution. This is done by letting functions call themselves after a timed delay: &lt;br /&gt;
&lt;br /&gt;
 var loop = func {&lt;br /&gt;
     print(&amp;quot;this line appears once every two seconds&amp;quot;);&lt;br /&gt;
     settimer(loop, 2);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 loop();        # start loop&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;settimer&amp;lt;/tt&amp;gt; function expects a ''function object'' (&amp;lt;tt&amp;gt;loop&amp;lt;/tt&amp;gt;), not a function call (&amp;lt;tt&amp;gt;loop()&amp;lt;/tt&amp;gt;) (though it is possible to make a function call return a function object--an advanced functional programming technique that you won't need to worry about if you're just getting started with Nasal). &lt;br /&gt;
&lt;br /&gt;
The fewer code FlightGear has to execute, the better, so it is desirable to run loops only when they are needed. But how does one stop a loop? A once triggered timer function can't be revoked. But one can let the loop function check an outside variable and refuse calling itself, which makes the loop chain die off:&lt;br /&gt;
&lt;br /&gt;
 var running = 1;&lt;br /&gt;
 var loop = func {&lt;br /&gt;
     if (running) {&lt;br /&gt;
         print(&amp;quot;this line appears once every two seconds&amp;quot;);&lt;br /&gt;
         settimer(loop, 2);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 loop();        # start loop ...&lt;br /&gt;
 ...&lt;br /&gt;
 running = 0;   # ... and let it die&lt;br /&gt;
&lt;br /&gt;
Unfortunately, this method is rather unreliable. What if the loop is &amp;quot;stopped&amp;quot; and a new instance immediately started again? Then the ''running'' variable would be ''1'' again, and a pending old loop call, which should really finish this chain, would happily continue. And the new loop chain would start, too, so that we would end up with two loop chains.&lt;br /&gt;
&lt;br /&gt;
This can be solved by providing each loop chain with a ''loop identifier'' and letting the function end itself if the id doesn't match the global loop-id. Self-called loop functions need to inherit the chain id. So, every time the global loop id is increased, all loop chains die, and a new one can immediately be started.&lt;br /&gt;
&lt;br /&gt;
 var loopid = 0;&lt;br /&gt;
 var loop = func(id) {&lt;br /&gt;
     id == loopid or return;           # stop here if the id doesn't match the global loop-id&lt;br /&gt;
     ...&lt;br /&gt;
     settimer(func { loop(id) }, 2);   # call self with own loop id&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 loop(loopid);       # start loop&lt;br /&gt;
 ...&lt;br /&gt;
 loopid += 1;        # this kills off all pending loops, as none can have this new identifier yet&lt;br /&gt;
 ...&lt;br /&gt;
 loop(loopid);       # start new chain; this can also be abbreviated to:  loop(loopid += 1);&lt;br /&gt;
&lt;br /&gt;
[[Nasal_scripting_language#settimer.28.29|More information about the settimer function is below]]&lt;br /&gt;
&lt;br /&gt;
== OOP - Object Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
In Nasal, objects (&amp;quot;classes&amp;quot;) are regular hashes. Self-reference and inheritance are implemented through special variables &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt;. To get a better understanding of the concept, let's start with the very basics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Hashes ===&lt;br /&gt;
&lt;br /&gt;
Hashes, also known as &amp;quot;dictionaries&amp;quot; in Python or &amp;quot;maps&amp;quot; in C++/STL are data structures that hold key/value pairs in a way that allows quick access to a value via its key.&lt;br /&gt;
&lt;br /&gt;
 var airport = {&lt;br /&gt;
     &amp;quot;LOXZ&amp;quot;: &amp;quot;Zeltweg&amp;quot;,&lt;br /&gt;
     &amp;quot;LOWI&amp;quot;: &amp;quot;Innsbruck&amp;quot;,&lt;br /&gt;
     &amp;quot;LOXL&amp;quot;: &amp;quot;Linz Hoersching&amp;quot;,     # the last comma is optional&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 print(airport[&amp;quot;LOXZ&amp;quot;]);            # prints &amp;quot;Zeltweg&amp;quot;&lt;br /&gt;
 airport[&amp;quot;LOXA&amp;quot;] = &amp;quot;Aigen&amp;quot;;         # adds LOXA to the hash&lt;br /&gt;
&lt;br /&gt;
The built-in function keys() returns a vector with the keys of the hash.  The function values() returns a vector with the values of the hash. For example:&lt;br /&gt;
&lt;br /&gt;
  debug.dump (keys(airport)); #prints ['LOXZ', 'LOWI', 'LOXL']&lt;br /&gt;
  debug.dump (values (airport)); #prints ['Zeltweg', 'Innsbruck', 'Linz Hoersching'] &lt;br /&gt;
&lt;br /&gt;
The quotes around keys can be left away in a hash definition if the key is a valid variable name or a number. This works just as well:&lt;br /&gt;
&lt;br /&gt;
 var airport = {&lt;br /&gt;
     LOXZ: &amp;quot;Zeltweg&amp;quot;,&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
There's also an alternative way to access hash members if the keys are valid variable names: &amp;lt;tt&amp;gt;airport.LOXI&amp;lt;/tt&amp;gt; can be used instead of &amp;lt;tt&amp;gt;airport[&amp;quot;LOXI&amp;quot;]&amp;lt;/tt&amp;gt;. There is a difference, though, which is described in the next section.&lt;br /&gt;
&lt;br /&gt;
Note that assigning a hash (or a vector) to another variable does never ''copy'' the contents. It only creates another reference to the same data structure. So manipulating the hash via its new name does in fact change the one, original hash.&lt;br /&gt;
&lt;br /&gt;
 var a = airport;&lt;br /&gt;
 a.LOXL = &amp;quot;Linz&amp;quot;;           # same as airport.LOXL!&lt;br /&gt;
 print(airport.LOXL);       # prints now &amp;quot;Linz&amp;quot;, not &amp;quot;Linz Hoersching&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(True copies of vectors can be made by assigning a full slice: &amp;lt;tt&amp;gt;var copy = vec[:]&amp;lt;/tt&amp;gt;. There's no such method for hashes.)&lt;br /&gt;
&lt;br /&gt;
=== Self-reference: &amp;quot;&amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt;&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
Values stored in a hash can be of any type, even of type ''function''. Member functions (&amp;quot;methods&amp;quot;) can reference their own enclosing hash via reserved keyword &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt;. This is comparable to the &amp;lt;tt&amp;gt;this&amp;lt;/tt&amp;gt; keyword in C++ classes, or the &amp;lt;tt&amp;gt;self&amp;lt;/tt&amp;gt; keyword in Python.&lt;br /&gt;
&lt;br /&gt;
 var value = &amp;quot;test&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
 var data = {&lt;br /&gt;
     value: 23,                         # scalar member variable&lt;br /&gt;
     write1: func { print(value); },    # function member&lt;br /&gt;
     write2: func { print(me.value); }, # function member&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 data.write1();     # prints &amp;quot;test&amp;quot;&lt;br /&gt;
 data.write2();     # prints 23&lt;br /&gt;
&lt;br /&gt;
The above example is already a simple form of an object. It has its own variable namespace (''data''), its own methods, and it can be passed around by-reference as one unit. Such classes are sometimes called ''singleton classes'', as they are unique, with no independent class instances. They mostly serve as a way to keep data and methods nicely encapsulated within a Nasal module. Often they contain a method for initializing, which is usually called &amp;lt;tt&amp;gt;init&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Inheritance: &amp;quot;&amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt;&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
What we learned about &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; in the last section is only half the truth. &amp;quot;me&amp;quot; doesn't only reference an object's own hash, but also one or more parent hashes. &amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt; is another reserved keyword. It denotes a vector referencing other object hashes, which are &amp;quot;inherited&amp;quot; that way.&lt;br /&gt;
&lt;br /&gt;
Please note that Nasal's currently supported form of encapsulation does not provide support for any form of data/information hiding (restricting access), i.e. all hash fields (but also all hash methods) are always publicly accessible (so there's nothing like the &amp;quot;private&amp;quot; or &amp;quot;protected&amp;quot; keywords in C++: in this sense, Nasal's inheritance mechanism can be thought of like C++ structs which are also public by default).&lt;br /&gt;
&lt;br /&gt;
The major difference being, that all members (functions and fields) are also always '''mutable''', which means that functions can modify the behavior of other functions quite easily, this also applies to the parents vector, too.&lt;br /&gt;
&lt;br /&gt;
 var parent_object = {&lt;br /&gt;
     value: 123,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var object = {&lt;br /&gt;
     parents: [parent_object],&lt;br /&gt;
     write: func { print(me.value) },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 object.write();    # prints 123&lt;br /&gt;
&lt;br /&gt;
Even though &amp;lt;tt&amp;gt;object&amp;lt;/tt&amp;gt; itself doesn't contain a member &amp;lt;tt&amp;gt;value&amp;lt;/tt&amp;gt;, it finds and uses the one of its parent object. &amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt; is a vector that can contain several parent objects. These are then searched in the order from left to right, until a matching member variable or method is found. Each of the parents can itself have parents, which are all recursively searched.&lt;br /&gt;
&lt;br /&gt;
In the section about hashes it was said that hash members can be accessed in two alternative ways, and that's also true for methods. &amp;lt;tt&amp;gt;object.write()&amp;lt;/tt&amp;gt; could also be called as &amp;lt;tt&amp;gt;object[&amp;quot;write&amp;quot;]()&amp;lt;/tt&amp;gt;. But only in the first form will members also be searched in parent hashes if not found in the base hash, whereas the second form creates an error if it's not a direct member.&lt;br /&gt;
&lt;br /&gt;
=== Creating class instances ===&lt;br /&gt;
&lt;br /&gt;
With &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt; we can implement a class object and create independent instances from that:&lt;br /&gt;
&lt;br /&gt;
 var Class = {&lt;br /&gt;
     write:     func { print(me.value); },&lt;br /&gt;
     increment: func { me.value += 1; },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var instance1 = { parents: [Class], value: 123 };&lt;br /&gt;
 var instance2 = { parents: [Class], value: 456 };&lt;br /&gt;
 &lt;br /&gt;
 instance1.write();    # prints 123&lt;br /&gt;
 instance2.write();    # prints 456&lt;br /&gt;
&lt;br /&gt;
As you can see, the two class instances are separate, independent objects, which share another object as parent -- they &amp;quot;inherit&amp;quot; from object &amp;lt;tt&amp;gt;Class&amp;lt;/tt&amp;gt;. One can now easily change members of any of these three objects. The following will redefine the parent's &amp;lt;tt&amp;gt;write&amp;lt;/tt&amp;gt; method, and all instances will automatically use this new version:&lt;br /&gt;
&lt;br /&gt;
 Class.write = func { print(&amp;quot;VALUE = &amp;quot; ~ me.value) }&lt;br /&gt;
&lt;br /&gt;
But one can also add a method to just one instance:&lt;br /&gt;
&lt;br /&gt;
 instance1.write = func { print(&amp;quot;VALUE = &amp;quot; ~ me.value) }&lt;br /&gt;
&lt;br /&gt;
Because &amp;lt;tt&amp;gt;instance1&amp;lt;/tt&amp;gt; does now have its own &amp;lt;tt&amp;gt;write&amp;lt;/tt&amp;gt; method, the parents won't be searched for one, so &amp;lt;tt&amp;gt;Class.write&amp;lt;/tt&amp;gt; is now overridden by &amp;lt;tt&amp;gt;instance1&amp;lt;/tt&amp;gt;'s own method. Nothing changed for &amp;lt;tt&amp;gt;instance2&amp;lt;/tt&amp;gt; -- it will still only find and use &amp;lt;tt&amp;gt;Class.write&amp;lt;/tt&amp;gt; via its parent.&lt;br /&gt;
&lt;br /&gt;
Note, the we couldn't create a class instance by simple assignment, because, as we learned above, this wouldn't create a separate copy of the Class object. All &amp;quot;instances&amp;quot; would reference the same hash!&lt;br /&gt;
&lt;br /&gt;
 var bad_instance1 = Class;   # bad&lt;br /&gt;
 var bad_instance2 = Class;   # bad&lt;br /&gt;
 &lt;br /&gt;
 bad_instance1.value = 123;   # sets Class.value to 123&lt;br /&gt;
 bad_instance2.value = 456;   # sets Class.value to 456&lt;br /&gt;
 &lt;br /&gt;
 bad_instance1.write();       # prints 456, not 123&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
Defining each class instance by explicitly creating a hash with parents is clumsy. It is nicer to have a function that does that for us. Then we can also use function arguments to initialize members of this instance.&lt;br /&gt;
&lt;br /&gt;
 var new_class = func(val) {&lt;br /&gt;
     return { parents: [Class], value: val };&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 var instance1 = new_class(123);&lt;br /&gt;
 var instance2 = new_class(456);&lt;br /&gt;
 &lt;br /&gt;
 instance1.write();   # prints 123&lt;br /&gt;
 instance2.write();   # prints 456&lt;br /&gt;
&lt;br /&gt;
Because the class generating function &amp;lt;tt&amp;gt;new_class()&amp;lt;/tt&amp;gt; really belongs to class &amp;lt;tt&amp;gt;Class&amp;lt;/tt&amp;gt;, it would be nicer to put it into the class hash as well. In this case we call it a class &amp;quot;constructor&amp;quot;, and as a convention, give it the name ''new''. It could have any name, though, and there could be more than one constructor.&lt;br /&gt;
&lt;br /&gt;
 var Class = {&lt;br /&gt;
     new: func(val) {&lt;br /&gt;
         return { parents: [Class], value: val };&lt;br /&gt;
     },&lt;br /&gt;
     write: func {&lt;br /&gt;
         print(&amp;quot;VALUE=&amp;quot; ~ me.value);&lt;br /&gt;
     },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var instance1 = Class.new(123);&lt;br /&gt;
 var instance2 = Class.new(456);&lt;br /&gt;
&lt;br /&gt;
As you can see, &amp;lt;tt&amp;gt;new()&amp;lt;/tt&amp;gt; doesn't return a copy of &amp;lt;tt&amp;gt;Class&amp;lt;/tt&amp;gt;, but rather a small hash that contains only a list of parents and one individual member &amp;lt;tt&amp;gt;value&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Classes aren't always as simple as in our example. Usually they contain several members, of which some may have yet to be calculated in the constructor. In that case it's easier to create a local object hash first, and to let the constructor finally return it. Such local hashes are often named &amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt; (as a short reference to &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt;), or &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 var Class = {&lt;br /&gt;
     new: func(val) {&lt;br /&gt;
         var m = { parents: [Class] };&lt;br /&gt;
         m.value = val;&lt;br /&gt;
         return m;&lt;br /&gt;
     },&lt;br /&gt;
     write: func {&lt;br /&gt;
         print(&amp;quot;VALUE=&amp;quot; ~ me.value);&lt;br /&gt;
     },&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
This last example is the most frequently used form of class definitions in FlightGear-Nasal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Destructor ===&lt;br /&gt;
&lt;br /&gt;
There's no such thing in Nasal. In other languages destructors are automatically called when the class gets destroyed, so that memory and other resources that were allocated by the constructor can be freed. In Nasal that's all done by the Garbage Collector (GC), anyway. In the FlightGear context, however, there ''are'' resources that should get freed. Listeners should get removed, self-calling functions (&amp;quot;loops&amp;quot;) stopped. For that it's recommended to create a destructor function and to call that manually. Such functions are often called &amp;lt;tt&amp;gt;del&amp;lt;/tt&amp;gt;, similar to Python and to pair nicely with the three-letter constructor name &amp;lt;tt&amp;gt;new&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Memory management ===&lt;br /&gt;
&lt;br /&gt;
Finally, as you know now, Nasal, being a dynamic programming language, doesn't require or support any manual memory management, so unlike C++, you don't need to call operators like &amp;quot;new&amp;quot; or &amp;quot;delete&amp;quot; to allocate or free your memory.&lt;br /&gt;
&lt;br /&gt;
However, if you do know that you don't need a certain variable anymore, you can certainly give a hint to the built-in garbage collector to free it, by assigning a &amp;quot;nil&amp;quot; value to it. &lt;br /&gt;
&lt;br /&gt;
This can certainly pay off when using more complex data structures such as nested vectors or hashes, because it will tell the built-in garbage collector to remove all references to the corresponding symbols, so that they can be freed.&lt;br /&gt;
&lt;br /&gt;
It is also possible to make use of Nasal's delete() function to remove a symbol from a namespace (hash).&lt;br /&gt;
&lt;br /&gt;
So, if you are concerned about your script's memory requirements, using a combination of setting symbols to nil, or deleting them as appropriate, would allow you to create helper functions for freeing data structures easily.&lt;br /&gt;
&lt;br /&gt;
In addition, it is probably worth noting that this is also the only way to sanely reset an active Nasal namespace or even the whole interpreter. You need to do this in order to reload or re-initialize your code without restarting the whole FlightGear session [[Nasal_scripting_language#Managing_timers_and_listeners]].&lt;br /&gt;
&lt;br /&gt;
Obviously, you should first of all ensure that there is no more code running, this includes any registered listeners or timers, but also any others loops or recursive functions.&lt;br /&gt;
&lt;br /&gt;
Thus, if you'd like to reload a Nasal source file at run time, you should disable all running code, and then reset the corresponding namespace, too. This is to ensure that you get a clean and consistent namespace.&lt;br /&gt;
&lt;br /&gt;
Nasal provides a number of core library functions to manipulate namespaces, such as:&lt;br /&gt;
&lt;br /&gt;
* caller() - to get a strack trace of active functions currently on the Nasal stack&lt;br /&gt;
* compile() - to compile new Nasal code &amp;quot;on the fly&amp;quot;, i.e. dynamically from a string&lt;br /&gt;
* closure() - to query the lexical namespace of active functions&lt;br /&gt;
* bind() - to create new function objects&lt;br /&gt;
&lt;br /&gt;
More information is available here: http://www.plausible.org/nasal/lib.html&lt;br /&gt;
&lt;br /&gt;
If, on the other hand, you are using these data structures in some repeated fashion, it might make sense to keep the data structure itself around and simply re-use it next time (overwriting data as required), instead of always allocating/creating a new one, this is called &amp;quot;caching&amp;quot; and can pay off from a performance perspective.&lt;br /&gt;
&lt;br /&gt;
=== Multiple inheritance ===&lt;br /&gt;
&lt;br /&gt;
A class can inherit from one or more other classes. It can then access all methods and class members of all parent classes, but also override them and add additional members.&lt;br /&gt;
&lt;br /&gt;
 var A = {                                            # simple class A&lt;br /&gt;
     new: func {&lt;br /&gt;
         return { parents: [A] };&lt;br /&gt;
     },&lt;br /&gt;
     alpha: func print(&amp;quot;\tALPHA&amp;quot;),&lt;br /&gt;
     test:  func print(&amp;quot;\tthis is A.test&amp;quot;),&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var B = {                                            # simple class B&lt;br /&gt;
     new: func(v) {                                   # ... whose constructor takes an argument&lt;br /&gt;
         return { parents: [B], value: v };&lt;br /&gt;
     },&lt;br /&gt;
     bravo: func print(&amp;quot;\tBRAVO&amp;quot;),&lt;br /&gt;
     test:  func print(&amp;quot;\tthis is B.test&amp;quot;),&lt;br /&gt;
     write: func print(&amp;quot;\tmy value is: &amp;quot;, me.value),&lt;br /&gt;
 },&lt;br /&gt;
 &lt;br /&gt;
 var C = {                                            # class C that inherits ...&lt;br /&gt;
     new: func(v) {&lt;br /&gt;
         return { parents: [C, A.new(), B.new(v)] };  # ... from class A and B&lt;br /&gt;
     },&lt;br /&gt;
     charlie: func print(&amp;quot;\tCHARLIE&amp;quot;),&lt;br /&gt;
     test:    func print(&amp;quot;\tthis is C.test&amp;quot;),         # overrides A.test() and B.test()&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 print(&amp;quot;A instance&amp;quot;);&lt;br /&gt;
 var a = A.new();&lt;br /&gt;
 a.alpha();&lt;br /&gt;
 &lt;br /&gt;
 print(&amp;quot;B instance&amp;quot;);&lt;br /&gt;
 var b = B.new(123);&lt;br /&gt;
 b.bravo();&lt;br /&gt;
 b.write();&lt;br /&gt;
 &lt;br /&gt;
 print(&amp;quot;C instance&amp;quot;);&lt;br /&gt;
 var c = C.new(456);&lt;br /&gt;
 c.alpha();                        # use alpha from the A parent&lt;br /&gt;
 c.bravo();                        # use bravo from the B parent&lt;br /&gt;
 c.charlie();                      # use charlie from C itself&lt;br /&gt;
 c.test();                         # use C.test(), which overrides A.test() and B.test()&lt;br /&gt;
 c.write();&lt;br /&gt;
&lt;br /&gt;
Even if a class overrides a method of a parent with the same name, the parent's version can still be accessed via &amp;lt;tt&amp;gt;parents&amp;lt;/tt&amp;gt; vector.&lt;br /&gt;
&lt;br /&gt;
 c.test()               # use C.test()&lt;br /&gt;
 c.parents[0].test();   # use C.test()&lt;br /&gt;
 c.parents[1].test();   # use A.test()&lt;br /&gt;
 c.parents[2].test();   # use B.test()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== More on methods ===&lt;br /&gt;
&lt;br /&gt;
Methods are function members of a class hash. They can access other class members via the &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; variable, which is a reference to the class hash. For this reason, a method returning &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; can be used like the class itself, and one can apply further methods to the return value (this is usually called &amp;quot;method chaining&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
 var Object = {&lt;br /&gt;
     new: func(coords...) {&lt;br /&gt;
         return { parents: [Object], coords: coords };&lt;br /&gt;
     },&lt;br /&gt;
     rotate: func(angle) {&lt;br /&gt;
         # do the rotation&lt;br /&gt;
         return me;&lt;br /&gt;
     },&lt;br /&gt;
     scale: func(factor) {&lt;br /&gt;
         # do the scaling&lt;br /&gt;
         return me;&lt;br /&gt;
     },&lt;br /&gt;
     translate: func(x, y) {&lt;br /&gt;
         # do the translation&lt;br /&gt;
         return me;&lt;br /&gt;
     },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var triangle = Object.new([0, 0], [10, 0], [5, 7]);&lt;br /&gt;
 triangle.translate(-9, -4).scale(5).rotate(33).translate(9, 4);    # concatenated methods thanks to &amp;quot;me&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt;, however, is only known in the scope of the class. If a method is to be called as a listener callback or a timer function, &amp;lt;tt&amp;gt;me&amp;lt;/tt&amp;gt; has to get wrapped in a function, so that it's stored in the function closure.&lt;br /&gt;
&lt;br /&gt;
 var Manager = {&lt;br /&gt;
     new: func {&lt;br /&gt;
         return { parents: [Manager] };&lt;br /&gt;
     },&lt;br /&gt;
     start_timers: func {  &lt;br /&gt;
         settimer(do_stuff, 5);            # BAD: there's no &amp;quot;do_stuff&amp;quot; function in the scope&lt;br /&gt;
         settimer(me.do_stuff, 5);         # BAD: function exists, but &amp;quot;me&amp;quot; won't be known&lt;br /&gt;
                                           #      when the timer function is actually executed&lt;br /&gt;
         settimer(func me.do_stuff(), 5);  # GOOD: new function object packs &amp;quot;me&amp;quot; in the closure&lt;br /&gt;
 &lt;br /&gt;
         setlistener(&amp;quot;/sim/foo&amp;quot;, func me.do_stuff());  # GOOD  (same as with timers) &lt;br /&gt;
     },         &lt;br /&gt;
     do_stuff: func {&lt;br /&gt;
         print(&amp;quot;doing stuff&amp;quot;);&lt;br /&gt;
     },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var manager = Manager.new();&lt;br /&gt;
 manager.start_timers();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Click ''[http://wiki.flightgear.org/Namespaces_and_Methods#Methods here]'' for more information.'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Exception handling ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;die()&amp;lt;/tt&amp;gt; aborts a function with an error message (this can be compared to the throw() mechanism in C++).&lt;br /&gt;
&lt;br /&gt;
 var divide = func(a, b) {&lt;br /&gt;
     if (b == 0)&lt;br /&gt;
         die(&amp;quot;division by zero&amp;quot;);&lt;br /&gt;
     return a / b;     # this line won't be reached if b == 0&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
die() is also used internally by built-in extension functions or Nasal core functions. &amp;lt;tt&amp;gt;getprop(&amp;quot;/4me&amp;quot;)&amp;lt;/tt&amp;gt;, for example, dies with an error message ''&amp;quot;name must begin with alpha or '_'&amp;quot;''. Now assume we want to write a dialog where the user can type a property path into an input field, and we display the property's value in a popup dialog. What if the user typed an invalid path and we hand that over to &amp;lt;tt&amp;gt;getprop()&amp;lt;/tt&amp;gt;? We don't want Nasal to abort our code because of that. We want to display a nice error message instead. The &amp;lt;tt&amp;gt;call()&amp;lt;/tt&amp;gt; function can catch &amp;lt;tt&amp;gt;die()&amp;lt;/tt&amp;gt; exceptions:&lt;br /&gt;
&lt;br /&gt;
 var value = getprop(property);                                    # dies if 'property' is invalid&lt;br /&gt;
 var value = call(func getprop(property), nil, var err = []);      # catches invalid-property-exception and continues&lt;br /&gt;
&lt;br /&gt;
The second line calls getprop(property) just like the first, and returns its value. But if 'property' was invalid then the &amp;lt;tt&amp;gt;call()&amp;lt;/tt&amp;gt; function catches the exception and sets the 'err' vector instead. That vector remains empty on success.&lt;br /&gt;
&lt;br /&gt;
 if (size(err))&lt;br /&gt;
     print(&amp;quot;ERROR: bad property &amp;quot;, property, &amp;quot; (&amp;quot;, err[0], &amp;quot;)&amp;quot;);   # err[0] contains the die() message&lt;br /&gt;
 else&lt;br /&gt;
     print(&amp;quot;value of &amp;quot;, property, &amp;quot; is &amp;quot;, value);&lt;br /&gt;
&lt;br /&gt;
The first argument of &amp;lt;tt&amp;gt;call()&amp;lt;/tt&amp;gt; is a function object, the second a vector of function arguments (or ''nil''), and the third a vector where the function will return a possible error. For more information on the &amp;lt;tt&amp;gt;call()&amp;lt;/tt&amp;gt; function see the [http://plausible.org/nasal/lib.html Nasal library documentation]. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;die()&amp;lt;/tt&amp;gt; doesn't really care about what its argument is. It doesn't have to be a string, and can be any variable, for example a class. This can be used to pass values through a chain of functions.&lt;br /&gt;
&lt;br /&gt;
 var Error = {                                                             # exception class&lt;br /&gt;
     new: func(msg, number) {&lt;br /&gt;
         return { parents: [Error], message: msg, number: number };&lt;br /&gt;
     },&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var A = func(a) {&lt;br /&gt;
     if (a &amp;lt; 0)&lt;br /&gt;
         die(Error.new(&amp;quot;negative argument to A&amp;quot;, a));                      # throw Error&lt;br /&gt;
     return &amp;quot;A received &amp;quot; ~ a;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 var B = func(val) {&lt;br /&gt;
     var result = A(val);&lt;br /&gt;
     print(&amp;quot;B finished&amp;quot;);      # this line is not reached if A threw an exception&lt;br /&gt;
     return result;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 var value = call(B, [-4], var err = []);                                  # try B(-4)&lt;br /&gt;
 &lt;br /&gt;
 if (size(err)) {                                                          # catch (...)&lt;br /&gt;
     print(&amp;quot;ERROR: &amp;quot;, err[0].message, &amp;quot;; bad value was &amp;quot;, err[0].number);&lt;br /&gt;
     die(err[0]);                                                          # re-throw&lt;br /&gt;
 } else {&lt;br /&gt;
     print(&amp;quot;SUCCESS: &amp;quot;, value);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Listeners and Signals ==&lt;br /&gt;
&lt;br /&gt;
Listeners are callback functions that are attached to property nodes. They are triggered whenever the node is written to, or, depending on the listener type, also when children are added or removed, and when children are written to. Unlike polling loops, listeners don't have the least effect on the frame rate when they aren't triggered, which makes them preferable to monitor properties that aren't written to frequently. &lt;br /&gt;
&lt;br /&gt;
===setlistener() vs. _setlistener() ===&lt;br /&gt;
You are requested *not* to use the raw _setlistener() function, except in files in $FG_ROOT/Nasal/ when they are&lt;br /&gt;
needed immediately. Only then the raw function is required, as it doesn't rely on props.nas.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;tt&amp;gt;When listeners don't work&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Unfortunately, '''listeners don't work on so-called &amp;quot;tied&amp;quot; properties''' when the node value isn't set via property methods. (You can spot such tied properties by Ctrl-clicking the &amp;quot;.&amp;quot; entry in the property browser: they are marked with a &amp;quot;T&amp;quot;.) Most of the FDM properties are &amp;quot;tied&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Examples of properties where setlistener ''won't'' work: &lt;br /&gt;
&lt;br /&gt;
* /position/elevation-ft&lt;br /&gt;
* /ai/models/aircraft/orientation/heading-deg&lt;br /&gt;
* Any property node created as an alias&lt;br /&gt;
* Lots of others&lt;br /&gt;
&lt;br /&gt;
Before working to create a listener, always check whether a listener will work with that property node by control-clicking the &amp;quot;.&amp;quot; in property browser to put it into verbose mode, and then checking whether the property node for which you want to set up a listener is marked with a &amp;quot;T&amp;quot; or not.&lt;br /&gt;
&lt;br /&gt;
If you can't set a listener for a particular property, the alternative is to use settimer to set up a timer loop that checks the property value regularly. &lt;br /&gt;
&lt;br /&gt;
Listeners are most efficient for properties that change only occasionally.  No code is called at all during frames where the listener function is not called.  If the property value changes every frame, setting up a settimer loop with time=0 will execute every frame, just the same as setlistener would, and the settimer loop is more efficient than setting a listener. This is one reason the fact the setlistener doesn't work on certain tied and FDM properties is not a great loss.  See the section on timer loops below.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Syntax:&lt;br /&gt;
&lt;br /&gt;
 var listener_id = setlistener(&amp;lt;property&amp;gt;, &amp;lt;function&amp;gt; [, &amp;lt;startup=0&amp;gt; [, &amp;lt;runtime=1&amp;gt;]]);&lt;br /&gt;
&lt;br /&gt;
The first argument is a property node object (&amp;lt;tt&amp;gt;props.Node()&amp;lt;/tt&amp;gt; hash) or a property path. Because the node hash depends on the props.nas module being loaded, &amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; calls need to be deferred when used in an $FG_ROOT/Nasal/*.nas file, usually by calling them in a &amp;lt;tt&amp;gt;settimer(func {}, 0)&amp;lt;/tt&amp;gt; construction. To avoid that, one can use the raw &amp;lt;tt&amp;gt;_setlistener()&amp;lt;/tt&amp;gt; function directly, for which &amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; is a wrapper. The raw function does only accept node paths (e.g. &amp;quot;/sim/menubar/visibility&amp;quot;), but not props.Node() objects.&lt;br /&gt;
&lt;br /&gt;
The second argument is a function object (not a function call!). The &amp;lt;tt&amp;gt;func&amp;lt;/tt&amp;gt; keyword turns code into a function object.&lt;br /&gt;
&lt;br /&gt;
The third argument is optional. If it is non-null, then it causes the listener to be called initially. This is useful to let the callback function pick up the node value at startup.&lt;br /&gt;
&lt;br /&gt;
The fourth argument is optional, and defaults to 1. This means that the callback function will be executed whenever the property is written to, independent of the value. &lt;br /&gt;
&lt;br /&gt;
If the argument is set to 0, then the function will only get triggered if a value other than the current value is written to the node. This is important for cases where a property is written to once per frame, no matter if the value changed or not. YASim, for example, does that for /gear/gear/wow or /gear/launchbar/state.&lt;br /&gt;
So, this should be used for properties that are written to in every frame, although the written value is mostly the same. If the argument is 2, then also write access to children will get reported, as well as the creation and removal of children nodes.&lt;br /&gt;
&lt;br /&gt;
For both optional flags 0 means less calls, and 1 means more calls. The first is for startup behavior, and the second for runtime behavior.&lt;br /&gt;
&lt;br /&gt;
Here's a real-life example:&lt;br /&gt;
&lt;br /&gt;
  setlistener(&amp;quot;/gear/launchbar/state&amp;quot;, func {&lt;br /&gt;
      if (cmdarg().getValue() == &amp;quot;Engaged&amp;quot;)&lt;br /&gt;
          setprop(&amp;quot;/sim/messages/copilot&amp;quot;, &amp;quot;Engaged!&amp;quot;);&lt;br /&gt;
  }, 1, 0);&lt;br /&gt;
&lt;br /&gt;
YASim writes once per frame the string &amp;quot;Disengaged&amp;quot; to property /gear/launchbar/state. When an aircraft on deck of the aircraft carrier locks into the catapult, this changes to &amp;quot;Engaged&amp;quot;, which is then written again in every frame, until the aircraft leaves the catapult. Because the locking in is a bit difficult -- one has to target the sensitive area quite exactly --, it was desirable to get some quick feedback: a screen message that's also spoken by the Festival speech synthesis. With the args 1 and 0, this is done initially (for the unlikely case that we are locked in from the beginning), and then only when the node changes from an arbitrary value to &amp;quot;Engaged&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; returns a unique listener id on success, and &amp;lt;tt&amp;gt;nil&amp;lt;/tt&amp;gt; on error. The id is nothing else than a counter that is 0 for the first Nasal listener, 1 for the second etc. You need this id number to remove the listener. Most listeners are never removed, so that one doesn't assign the return value, but simply drop it.&lt;br /&gt;
&lt;br /&gt;
Listener callback functions can access up to four values via regular function arguments, the first two of which are property nodes in the form of a &amp;lt;tt&amp;gt;props.Node()&amp;lt;/tt&amp;gt; object hash.&lt;br /&gt;
&lt;br /&gt;
If you have set a callback function named ''myCallbackFunc'' via &amp;lt;tt&amp;gt;setlistener&amp;lt;/tt&amp;gt; (''setlistener(myNode, myCallbackFunc)''), you can use this syntax in the callback function:&lt;br /&gt;
&lt;br /&gt;
 myCallbackFunc ([&amp;lt;changed_node&amp;gt; [, &amp;lt;listened_to_node&amp;gt; [, &amp;lt;operation&amp;gt; [, &amp;lt;is_child_event&amp;gt;]]]])&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;removelistener()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Syntax:&lt;br /&gt;
&lt;br /&gt;
 var num_listeners = removelistener(&amp;lt;listener id&amp;gt;);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;removelistener()&amp;lt;/tt&amp;gt; takes one argument: the unique listener id that a &amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; call returned. It returns the number of remaining active Nasal listeners on success, &amp;lt;tt&amp;gt;nil&amp;lt;/tt&amp;gt; on error, or -1 if a listener function applies &amp;lt;tt&amp;gt;removelistener()&amp;lt;/tt&amp;gt; to itself. The fact that a listener can remove itself, can be used to implement a one-shot listener function:&lt;br /&gt;
&lt;br /&gt;
 var L = setlistener(&amp;quot;/some/property&amp;quot;, func {&lt;br /&gt;
     print(&amp;quot;I can only be triggered once.&amp;quot;);&lt;br /&gt;
     removelistener(L);&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Listener Examples ===&lt;br /&gt;
&lt;br /&gt;
The following example attaches an anonymous callback function to a &amp;quot;signal&amp;quot;. The function will be executed when FlightGear is closed.&lt;br /&gt;
&lt;br /&gt;
 setlistener(&amp;quot;/sim/signals/exit&amp;quot;, func { print(&amp;quot;bye!&amp;quot;) });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead of an anonymous function, a named function can be used as well:&lt;br /&gt;
&lt;br /&gt;
 var say_bye = func { print(&amp;quot;bye&amp;quot;) }&lt;br /&gt;
 setlistener(&amp;quot;/sim/signals/exit&amp;quot;, say_bye);&lt;br /&gt;
&lt;br /&gt;
Callback functions can, optionally, access up to four parameters which are handed over via regular function arguments. Many times none of these parameters is used at all, as in the above example.&lt;br /&gt;
&lt;br /&gt;
Most often, only the first parameter is used--which gives the node of the changed value.&lt;br /&gt;
&lt;br /&gt;
The following code attaches the monitor_course() function to a gps property, using the argument ''course'' to get the node with the changed value.&lt;br /&gt;
&lt;br /&gt;
 var monitor_course = func(course) {&lt;br /&gt;
     print(&amp;quot;Monitored course set to &amp;quot;, course.getValue());&lt;br /&gt;
 }&lt;br /&gt;
 var i = setlistener(&amp;quot;instrumentation/gps/wp/leg-course-deviation-deg&amp;quot;, monitor_course);&lt;br /&gt;
 &lt;br /&gt;
 # here the listener is active&lt;br /&gt;
 &lt;br /&gt;
 removelistener(i);                    # remove that listener again&lt;br /&gt;
&lt;br /&gt;
Here is code that accesses two arguments--the changed node and the listened-to node (these may be different when monitoring all children of a certain node)--and also shows how to monitor changes to a node including changes to children:&lt;br /&gt;
&lt;br /&gt;
 var monitor_course = func(course, flightinfo) {&lt;br /&gt;
     print(&amp;quot;One way to get the course setting: &amp;quot;, flightinfo.leg-course-deviation-deg.getValue());&lt;br /&gt;
     print(&amp;quot;Another way to get the same setting &amp;quot;, course.getValue());&lt;br /&gt;
 }&lt;br /&gt;
 var i = setlistener(&amp;quot;instrumentation/gps/wp&amp;quot;, monitor_course, 0, 2);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The function object doesn't need to be a separate, external function -- it can also be an anonymous function made directly in the &amp;lt;tt&amp;gt;setlistener()&amp;lt;/tt&amp;gt; call:&lt;br /&gt;
&lt;br /&gt;
 setlistener(&amp;quot;/sim/signals/exit&amp;quot;, func { print(&amp;quot;bye&amp;quot;) });    # say &amp;quot;bye&amp;quot; on exit&lt;br /&gt;
&lt;br /&gt;
Beware, however, that the contents of a function defined within the &amp;lt;tt&amp;gt;setlistener&amp;lt;/tt&amp;gt; call are not evaluated until the call is actually made. If, for instance, local variables change before the setlistener call happens, the call will reflect the current value of those variables ''at the time the callback function is called'', not the value ''at the time the listener was set''. &lt;br /&gt;
&lt;br /&gt;
For example, with this loop, the function will always return the value 10--even if mynode[1], mynode[2], mynode[3] or any of the others is the one that changed. It is because the contents of the setlistener are evaluated after the loop has completed running and at that point, i=10:&lt;br /&gt;
&lt;br /&gt;
 var output = func(number) {&lt;br /&gt;
     print(&amp;quot;mynode&amp;quot;, number, &amp;quot; has changed!&amp;quot;); #This won't work!&lt;br /&gt;
 }&lt;br /&gt;
 for(i=1; i &amp;lt;= 10; i = i+1) {&lt;br /&gt;
    var i = setlistener(&amp;quot;mynode[&amp;quot;~i~&amp;quot;]&amp;quot;, func{ output (i); });&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
You can also access the four available function properties (or just one, two, or three of them as you need) in your anonymous function. Here is an example that accesses the first value:&lt;br /&gt;
 &lt;br /&gt;
 for(i=1; i &amp;lt;= 10; i = i+1) {&lt;br /&gt;
    var i = setlistener(&amp;quot;mynode[&amp;quot;~i~&amp;quot;]&amp;quot;, func (changedNode) { print (changedNode.getPath() ~ &amp;quot; : &amp;quot; ~ changedNode.getValue()); });&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Attaching a function to a node that is specified as &amp;lt;tt&amp;gt;props.Node()&amp;lt;/tt&amp;gt; hash:&lt;br /&gt;
&lt;br /&gt;
 var node = props.globals.getNode(&amp;quot;/sim/signals/click&amp;quot;, 1);&lt;br /&gt;
 setlistener(node, func { gui.popupTip(&amp;quot;don't click here!&amp;quot;) });&lt;br /&gt;
&lt;br /&gt;
Sometimes it is desirable to call the listener function initially, so that it can pick up the node value. In the following example a listener watches the view number, and turns the HUD on in cockpit view, and off in all other views. It doesn't only do that on writing to &amp;quot;view-number&amp;quot;, but also once when the listener gets attached, thanks to the third argument &amp;quot;1&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 setlistener(&amp;quot;/sim/current-view/view-number&amp;quot;, func(n) {&lt;br /&gt;
     setprop(&amp;quot;/sim/hud/visibility[0]&amp;quot;, n.getValue() == 0);&lt;br /&gt;
 }, 1);&lt;br /&gt;
&lt;br /&gt;
There's no limit for listeners on a node. Several functions can get attached to one node, just as one function can get attached to several nodes. Listeners may write to the node they are listening to. This will not make the listener call itself causing an endless recursion.&lt;br /&gt;
&lt;br /&gt;
=== Signals ===&lt;br /&gt;
&lt;br /&gt;
In addition to &amp;quot;normal&amp;quot; nodes, there are &amp;quot;signal&amp;quot; nodes that were created solely for the purpose of having listeners attached:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/exit&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; on quitting FlightGear&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/reinit&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; right before resetting FlightGear (Shift-Esc), and to &amp;quot;false&amp;quot; afterwards&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/click&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; after a mouse click at the terrain. Hint that the geo coords for the click spot were updated and can be retrieved from /sim/input/click/{longitude-deg,latitude-deg,elevation-ft,elevation-m}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/screenshot&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; right before the screenshot is taken, and set to &amp;quot;false&amp;quot; after it. Can be used to hide and reveal dialogs etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/nasal-dir-initialized&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; after all Nasal &amp;quot;library&amp;quot; files in $FG_ROOT/Nasal/ were loaded and executed. It is only set once and can only be used to trigger listener functions that were defined in one of the Nasal files in that directory. After that signal was set&lt;br /&gt;
Nasal starts loading and executing aircraft Nasal files, and only later are &amp;lt;tt&amp;gt;settimer()&amp;lt;/tt&amp;gt; functions&lt;br /&gt;
called and the next signal is set:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/fdm-initialized&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; when then FDM has just finished its initialization&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/reinit-gui&amp;lt;/tt&amp;gt; ... set to &amp;quot;true&amp;quot; when the GUI has just been reset (e.g. via Help menu). This&lt;br /&gt;
is used by the gui.Dialog class to reload Nasal-loaded XML dialogs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/sim/signals/frame&amp;lt;/tt&amp;gt; ... triggered at the beginning of each iteration of the main loop (a.k.a. &amp;quot;frame&amp;quot;). This is meant for debugging purposes. Normally, one would just use a settimer() with interval 0 for the same effect. The difference is that the signal is guaranteed to be raised at a defined moment, while the timer call may change when subsystems are re-ordered.&lt;br /&gt;
&lt;br /&gt;
== FlightGear extension functions ==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;cmdarg()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
cmdarg() is a mechanism to pass arguments to a nasal script (wrapped in properties) instead of &amp;quot;normal&amp;quot; function parameters. Note that cmdarg() should be primarily used in Nasal code embedded in XML files and should be considered depreciated otherwise (see [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg18361.html] and [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg18361.html]).&lt;br /&gt;
&lt;br /&gt;
cmdarg() will keep working in (joystick) XML-'''bindings''' and on the top-level of embedded Nasal scripts (i.e. dialog and animation XML files).&lt;br /&gt;
&lt;br /&gt;
As such, the cmdarg() function is primarily used for listener callbacks declared in XML markup, cmdarg() returns the listened-to property as props.Node object, so you can use it with all its methods (see $FG_ROOT/Nasal/props.nas) for example:&lt;br /&gt;
&lt;br /&gt;
  print(cmdarg().getPath(), &amp;quot; has been changed to &amp;quot;, cmdarg().getValue())&lt;br /&gt;
&lt;br /&gt;
The cmdarg() function avoids that you have to type the exact same path twice (once here and once in the setlistener() command) and it makes clear that this is the listened to property. Also, you can use all the nice props.Node methods on cmdarg() directly:&lt;br /&gt;
&lt;br /&gt;
 setlistener(&amp;quot;/gear/launchbar/state&amp;quot;, func {&lt;br /&gt;
      if (cmdarg().getValue() == &amp;quot;Engaged&amp;quot;)&lt;br /&gt;
          setprop(&amp;quot;/sim/messages/copilot&amp;quot;, &amp;quot;Engaged!&amp;quot;);&lt;br /&gt;
  }, 1, 0);&lt;br /&gt;
&lt;br /&gt;
Use of cmdarg() outside of XML-bindings won't cause an error, but (still) return the last cmdarg() property. This just won't be the listened-to property anymore, but whatever the last legitimate cmdarg() user set. Most of the time it will be the property root of a joystick binding.&lt;br /&gt;
&lt;br /&gt;
Don't make any assumptions and use cmdarg() only in one of these cases:&lt;br /&gt;
&lt;br /&gt;
* binding: returns root of this binding's property branch. Needed for accessing an axis' value:         cmdarg().getNode(&amp;quot;setting&amp;quot;).getValue()&lt;br /&gt;
&lt;br /&gt;
* dialog xml files: returns root of that file's property branch in memory. This can be used to let embedded Nasal change the dialog (e.g. clear and build lists) before the final layout is decided&lt;br /&gt;
&lt;br /&gt;
* animation xml files: returns root of this model's place in /ai/models/ when used as AI/MP model. Examples:       /ai/models/multiplayer[3], /ai/models/tanker[1], etc. [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg14164.html]&lt;br /&gt;
&lt;br /&gt;
* AI aircraft XML files&lt;br /&gt;
&lt;br /&gt;
* remotely invoking Nasal code by setting properties using the built-in telnet daemon (RPC) [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg00150.html [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg00336.html].&lt;br /&gt;
&lt;br /&gt;
'''In all cases, the cmdarg() call must not be delayed until later using settimer() or setlistener(). Because later it'll again return some unrelated property!&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;fgcommand()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Runs an internal &amp;quot;fgcommand&amp;quot;, see $FG_ROOT/Docs/README.commands for a list of available commands: http://gitorious.org/fg/fgdata/blobs/master/Docs/README.commands&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;print()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Concatenates an arbitrary number of arguments to one string, appends a new-line, and prints it to the terminal. Returns the number of printed characters.&lt;br /&gt;
&lt;br /&gt;
 print(&amp;quot;Just&amp;quot;, &amp;quot; a &amp;quot;, &amp;quot;test&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;getprop()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Returns the node value for a given path, or &amp;lt;tt&amp;gt;nil&amp;lt;/tt&amp;gt; if the node doesn't exist or hasn't been initialized yet. &lt;br /&gt;
&lt;br /&gt;
 getprop(&amp;lt;path&amp;gt;);&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 print(&amp;quot;The frame rate is &amp;quot;, getprop(&amp;quot;/sim/frame-rate&amp;quot;), &amp;quot; FPS&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;setprop()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Sets a property value for a given node path string. Always returns nil.&lt;br /&gt;
&lt;br /&gt;
 setprop(&amp;lt;path&amp;gt; [, &amp;lt;path&amp;gt;, [...]], &amp;lt;value&amp;gt;);&lt;br /&gt;
&lt;br /&gt;
All arguments but the last are concatenated to a path string, with a slash (/) inserted between each element. The last value is written to the respective node. If the node isn't writable, then an error message is printed to the console.&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;tt&amp;gt;setprop()&amp;lt;/tt&amp;gt; concatenates a list of input arguments by means of inserting a &amp;quot;/&amp;quot; in between. That is nice for properties, as this slash is part of the tree. However, when one wants to make use of indices, like [0], one has to concatenate by hand (using &amp;quot;~&amp;quot;) ''inside'' one part of the string argument list. An example is:&lt;br /&gt;
&lt;br /&gt;
  var i = 4;&lt;br /&gt;
  setprop(&amp;quot;instrumentation&amp;quot;,&amp;quot;cdu&amp;quot;,&amp;quot;page[&amp;quot;~i~&amp;quot;]&amp;quot;,&amp;quot;title&amp;quot;,&amp;quot;MENU&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This results in instrumentation/cdu/page[4]/title = 'MENU' (string)&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
 setprop(&amp;quot;/sim/current-view/view-number&amp;quot;, 2);&lt;br /&gt;
 setprop(&amp;quot;/controls&amp;quot;, &amp;quot;engines/engine[0]&amp;quot;, &amp;quot;reverser&amp;quot;, 1);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Erasing a property from the property tree''': a property that has been created, for example through &amp;lt;tt&amp;gt;setprop()&amp;lt;/tt&amp;gt; can be erased via&lt;br /&gt;
&lt;br /&gt;
  props.globals.getNode(&amp;quot;foo/bar&amp;quot;).remove(); 		# take out the complete node&lt;br /&gt;
  props.globals.getNode(&amp;quot;/foo&amp;quot;).removeChild(&amp;quot;bar&amp;quot;); 	# take out a certain child node&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;settimer()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Runs a function after a given simulation time (default) or real time in seconds.&lt;br /&gt;
&lt;br /&gt;
 settimer(&amp;lt;function&amp;gt;, &amp;lt;time&amp;gt; [, &amp;lt;realtime=0&amp;gt;]);&lt;br /&gt;
&lt;br /&gt;
The first object is a function object (ie, &amp;quot;func { ... }&amp;quot;).  Note that this is different from a function call (ie, &amp;quot;func ( ... )&amp;quot;). If you don't understand what this means, just remember to always enclose the first argument in any call to settimer with the word &amp;quot;func&amp;quot; and braces &amp;quot;{ }&amp;quot;, and it will always work. For instance, if you want print the words &amp;quot;My result&amp;quot; in five seconds, use this code:&lt;br /&gt;
&lt;br /&gt;
 settimer ( func { print ( &amp;quot;My result&amp;quot;); }, 5);&lt;br /&gt;
&lt;br /&gt;
Inside the braces of the func object you can put any valid Nasal code, including a function call.  In fact, if you want to call a function with certain values as arguments, the way to do it is to turn it into a function object by enclosing it with a func{}, for example:&lt;br /&gt;
&lt;br /&gt;
 myarg1=&amp;quot;My favorite string&amp;quot;;&lt;br /&gt;
 myarg2=432;&lt;br /&gt;
 settimer ( func { myfunction ( myarg1, myarg2); }, 25);&lt;br /&gt;
&lt;br /&gt;
The third argument is optional and defaults to 0, which lets the time argument be interpreted as &amp;quot;seconds simulation time&amp;quot;. In this case the timer doesn't run when FlightGear is paused. For user interaction purposes (measuring key press time, displaying popups, etc.) one usually prefers real time.&lt;br /&gt;
&lt;br /&gt;
 # simulation time example&lt;br /&gt;
 var copilot_annoyed = func { setprop(&amp;quot;/sim/messages/copilot&amp;quot;, &amp;quot;Stop it! Immediately!&amp;quot;) }&lt;br /&gt;
 settimer(copilot_annoyed, 10);&lt;br /&gt;
&lt;br /&gt;
 # real time example&lt;br /&gt;
 var popdown = func ( tipArg ) { &lt;br /&gt;
  fgcommand(&amp;quot;dialog-close&amp;quot;, tipArg); &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 var selfStatusPopupTip = func (label, delay = 10, override = nil) {	&lt;br /&gt;
    var tmpl = props.Node.new({&lt;br /&gt;
            name : &amp;quot;PopTipSelf&amp;quot;, modal : 0, layout : &amp;quot;hbox&amp;quot;,&lt;br /&gt;
            y: 140,&lt;br /&gt;
            text : { label : label, padding : 6 }&lt;br /&gt;
    });&lt;br /&gt;
    if (override != nil) tmpl.setValues(override);&lt;br /&gt;
    &lt;br /&gt;
    popdown(tipArgSelf);&lt;br /&gt;
    fgcommand(&amp;quot;dialog-new&amp;quot;, tmpl);&lt;br /&gt;
    fgcommand(&amp;quot;dialog-show&amp;quot;, tipArgSelf);&lt;br /&gt;
 &lt;br /&gt;
    currTimerSelf += 1;&lt;br /&gt;
    var thisTimerSelf = currTimerSelf;&lt;br /&gt;
 &lt;br /&gt;
    # Final argument 1 is a flag to use &amp;quot;real&amp;quot; time, not simulated time&lt;br /&gt;
    settimer(func { if(currTimerSelf == thisTimerSelf) { popdown(tipArgSelf) } }, delay, 1);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
[[Nasal_scripting_language#settimer_loops|More information about best practices for using the settimer function to create loops in Nasal is elsewhere on this page.]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;systime()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Returns epoch time (time since 1972/01/01 00:00) in seconds as a floating point number with high resolution. This is useful for benchmarking purposes.&lt;br /&gt;
&lt;br /&gt;
  #benchmarking example:&lt;br /&gt;
  var start = systime();&lt;br /&gt;
  how_fast_am_I(123);&lt;br /&gt;
  var end = systime();&lt;br /&gt;
  print(&amp;quot;took &amp;quot;, end - start, &amp;quot; seconds&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;carttogeod()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Converts cartesian coordinates x/y/z to geodetic coordinates lat/lon/alt, which are returned as a vector. Units are degree and meter.&lt;br /&gt;
&lt;br /&gt;
 var geod = carttogeod(-2737504, -4264101, 3862172);&lt;br /&gt;
 print(&amp;quot;lat=&amp;quot;, geod[0], &amp;quot; lon=&amp;quot;, geod[1], &amp;quot; alt=&amp;quot;, geod[2]);&lt;br /&gt;
 &lt;br /&gt;
 # outputs&lt;br /&gt;
 lat=37.49999782141546 lon=-122.6999914632327 alt=998.6042055172776&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;geodtocart()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Converts geodetic coordinates lat/lon/alt to cartesian coordinates x/y/z. Units are degree and meter.&lt;br /&gt;
&lt;br /&gt;
 var cart = geodtocart(37.5, -122.7, 1000); # lat/lon/alt(m)&lt;br /&gt;
 print(&amp;quot;x=&amp;quot;, cart[0], &amp;quot; y=&amp;quot;, cart[1], &amp;quot; z=&amp;quot;, cart[2]);&lt;br /&gt;
 &lt;br /&gt;
 # outputs&lt;br /&gt;
 x=-2737504.667684828 y=-4264101.900993474 z=3862172.834656495&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;geodinfo()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Returns information about geodetic coordinates. Takes two arguments: lat, lon (in degree) and returns a vector with two entries, or nil if no information could be obtained because the terrain tile wasn't loaded. The first entry is the elevation (in meters) for the given point, and the second is a hash with information about the assigned material, or nil if there was no material information available, because there is, for instance, an untextured building at that spot or the scenery tile is not loaded.&lt;br /&gt;
&lt;br /&gt;
 var lat = getprop(&amp;quot;/position/latitude-deg&amp;quot;);&lt;br /&gt;
 var lon = getprop(&amp;quot;/position/longitude-deg&amp;quot;);&lt;br /&gt;
 var info = geodinfo(lat, lon);&lt;br /&gt;
 &lt;br /&gt;
 if (info != nil) {&lt;br /&gt;
     print(&amp;quot;the terrain under the aircraft is at elevation &amp;quot;, info[0], &amp;quot; m&amp;quot;);&lt;br /&gt;
     if (info[1] != nil)&lt;br /&gt;
         print(&amp;quot;and it is &amp;quot;, info[1].solid ? &amp;quot;solid ground&amp;quot; : &amp;quot;covered by water&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A full data set looks like this:&lt;br /&gt;
&lt;br /&gt;
 debug.dump(geodinfo(lat, lon));&lt;br /&gt;
 &lt;br /&gt;
 # outputs&lt;br /&gt;
 [ 106.9892101062052, { light_coverage : 0, bumpiness : 0.5999999999999999, load_resistance : 1e+30,&lt;br /&gt;
 solid : 0,  names : [ &amp;quot;Lake&amp;quot;, &amp;quot;Pond&amp;quot;, &amp;quot;Reservoir&amp;quot;, &amp;quot;Stream&amp;quot;, &amp;quot;Canal&amp;quot; ], friction_factor : 1, &lt;br /&gt;
 rolling_friction : 1.5 } ]&lt;br /&gt;
&lt;br /&gt;
Note that geodinfo is a *very* CPU intensive operation, particularly in FG 2.4.0 and earlier, so use sparingly ([http://flightgear.org/forums/viewtopic.php?f=4&amp;amp;p=135044#p135044 discussion here]).&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;parsexml()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
This function is an interface to the built-in [http://expat.sourceforge.net/ Expat XML parser]. It takes up to five arguments. The first is a mandatory absolute path to an XML file, the remaining four are optional callback functions, each of which can be nil (which is also the default value).&lt;br /&gt;
&lt;br /&gt;
 var ret = parsexml(&amp;lt;path&amp;gt; [, &amp;lt;start-elem&amp;gt; [, &amp;lt;end-elem&amp;gt; [, &amp;lt;data&amp;gt; [, &amp;lt;pi&amp;gt; ]]]]);&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;start-elem&amp;gt;  ... called for every starting tag with two arguments: the tag name, and an attribute hash&lt;br /&gt;
 &amp;lt;end-elem&amp;gt;    ... called for every ending tag with one argument: the tag name&lt;br /&gt;
 &amp;lt;data&amp;gt;        ... called for every piece of data with one argument: the data string&lt;br /&gt;
 &amp;lt;pi&amp;gt;          ... called for every &amp;quot;processing information&amp;quot; with two args: target and data string&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;ret&amp;gt;         ... the return value is nil on error, and the &amp;lt;path&amp;gt; otherwise&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 var start = func(name, attr) {&lt;br /&gt;
     print(&amp;quot;starting tag &amp;quot;, name);&lt;br /&gt;
     foreach (var a; keys(attr))&lt;br /&gt;
         print(&amp;quot;\twith attribute &amp;quot;, a, &amp;quot;=&amp;quot;, attr[a]);&lt;br /&gt;
 }&lt;br /&gt;
 var end = func(name) { print(&amp;quot;ending tag &amp;quot;, name) }&lt;br /&gt;
 var data = func(data) { print(&amp;quot;data=&amp;quot;, data) }&lt;br /&gt;
 var pi = func(target, data) { print(&amp;quot;processing instruction: target=&amp;quot;, target, &amp;quot; data=&amp;quot;, data) }&lt;br /&gt;
 parsexml(&amp;quot;/tmp/foo.xml&amp;quot;, start, end, data, pi);&lt;br /&gt;
&lt;br /&gt;
=== airportinfo() ===&lt;br /&gt;
Function for retrieval of airport/runway information.&lt;br /&gt;
Usage:&lt;br /&gt;
&lt;br /&gt;
  var apt = airportinfo(&amp;quot;KHAF&amp;quot;);   # get info about KHAF&lt;br /&gt;
  var apt = airportinfo(lat, lon); # get info about apt closest to lat/lon&lt;br /&gt;
  var apt = airportinfo();         # get info about apt closest to aircraft  &lt;br /&gt;
&lt;br /&gt;
The command debug.dump(airportinfo(&amp;quot;KHAF&amp;quot;)) outputs this:&lt;br /&gt;
&lt;br /&gt;
  { lon : -122.4962626410256, lat : 37.51343502564102, has_metar : 0,&lt;br /&gt;
  runways : { 12 : { stopway2 : 0, threshold1 : 232.5624,&lt;br /&gt;
  lon : -122.5010889999999, lat : 37.513831, stopway1 : 0, width : 45.72,&lt;br /&gt;
  threshold2 : 232.5624, heading : 138.1199999999999, length : 1523.0856 } },&lt;br /&gt;
  elevation : 20.42159999999999, id : &amp;quot;KHAF&amp;quot;, name : &amp;quot;Half Moon Bay&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
That is: a hash with elements lat/lon/elev/id/name/has_metar for the&lt;br /&gt;
airport, and a hash with runways, each of which consists of lat/lon/&lt;br /&gt;
/length/width/heading/threshold[12]/stopway[12]. Only one side of each&lt;br /&gt;
runway is listed -- the other can easily be deduced.&lt;br /&gt;
&lt;br /&gt;
==Built-in functions==&lt;br /&gt;
&lt;br /&gt;
===sort(vector, function)===&lt;br /&gt;
Creates a new vector containing the elements in the input vector sorted in ascending order according to the rule given by function, which takes two arguments (elements of the input vector) and should return less than zero, zero, or greater than zero if the first argument is, respectively, less than, equal to, or greater than the second argument. Despite being implemented with ANSI C qsort(), the sort is stable; &amp;quot;equal&amp;quot; elements in the output vector will appear in the same relative order as they do in the input.&lt;br /&gt;
&lt;br /&gt;
Because you can define the sort function, sort allows you to create a list of keys sorting a hash by any criterion--by key, value, or (if, for instance the hash values are hashes themselves) any subvalue.&lt;br /&gt;
&lt;br /&gt;
 vec = [100,24,45];&lt;br /&gt;
 sortvec = sort (vec, func (a,b) cmp (a,b));&lt;br /&gt;
 debug.dump (sortvec); #output is [24,45,100]&lt;br /&gt;
&lt;br /&gt;
Here is an example of how to output the contents of a hash in sorted order.  Note that the function does not actually sort the hash but returns a list of the hash keys in sorted order.&lt;br /&gt;
&lt;br /&gt;
 var airport = {&lt;br /&gt;
   &amp;quot;LOXZ&amp;quot;: &amp;quot;Zeltweg&amp;quot;,&lt;br /&gt;
   &amp;quot;LOWI&amp;quot;: &amp;quot;Innsbruck&amp;quot;,&lt;br /&gt;
   &amp;quot;LOXL&amp;quot;: &amp;quot;Linz Hoersching&amp;quot;,     # the last comma is optional&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 var sortedkeys= sort (keys(airport), func (a,b) cmp (airport[a], airport[b]));&lt;br /&gt;
 &lt;br /&gt;
 foreach (var i; sortedkeys) &lt;br /&gt;
  print (i, &amp;quot;: &amp;quot;, airport[i]);&lt;br /&gt;
&lt;br /&gt;
The output is:&lt;br /&gt;
&lt;br /&gt;
   LOWI: Innsbruck&lt;br /&gt;
   LOXL: Linz Hoersching&lt;br /&gt;
   LOXZ: Zeltweg  &lt;br /&gt;
&lt;br /&gt;
If the hash values are themselves hashes, sorting by any of the subvalues is possible.  For example:&lt;br /&gt;
&lt;br /&gt;
 var airport = {&lt;br /&gt;
    &amp;quot;LOXZ&amp;quot;: {city: &amp;quot;Zeltweg&amp;quot;, altitude_m: 1300 },&lt;br /&gt;
    &amp;quot;LOWI&amp;quot;: {city: &amp;quot;Innsbruck&amp;quot;, altitude_m: 2312 }, &lt;br /&gt;
    &amp;quot;LOXL&amp;quot;: {city: &amp;quot;Linz Hoersching&amp;quot;, altitude_m: 1932 },&lt;br /&gt;
 };&lt;br /&gt;
  &lt;br /&gt;
 #return a list of the hash keys sorted by altitude_m&lt;br /&gt;
 var sortedkeys= sort (keys(airport), func (a,b) airport[a].altitude_m - airport[b].altitude_m);&lt;br /&gt;
  &lt;br /&gt;
 foreach (var i; sortedkeys) &lt;br /&gt;
  print (i, &amp;quot;: &amp;quot;, airport[i].city, &amp;quot;, &amp;quot;, airport[i].altitude_m);&lt;br /&gt;
&lt;br /&gt;
Note that ''sort'' will return errors, and in FG 2.4.0 may even stop working, if the sort function you provide returns errors.  A common cause of this is if your sort vector contains both string and numeric values.  The cmp function will return an error for numeric values, and arithmetic operations you may use to sort numeric values will return errors if performed on a string.  The error in these cases is typically &amp;quot;function/method call on uncallable object&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Other useful built-in functions ===&lt;br /&gt;
&lt;br /&gt;
Other basic built-in Nasal functions such as append, setsize, subvec, typeof, contains, delete, int, num, keys, pop, size, streq, cmp, substr, sprintf, find, split, rand, call, die, bind, math.sin, math.pi, math.exp, math.ln math.e, io.read, io.write, regex.exec, and others of that sort, [http://www.plausible.org/nasal/lib.html are detailed in this external document].&lt;br /&gt;
&lt;br /&gt;
=== Useful functions in the Nasal directory ===&lt;br /&gt;
Other functions are available in the Nasal files found in the Nasal directory of a FlightGear install.  Simply open those Nasal files in text editor to see what is inside.  Reference those functions by putting the filename in front of the function, method, variable, or object you wish to use.  For instance, to use the method Coord.new() in the file geo.nas, you simply write:&lt;br /&gt;
&lt;br /&gt;
 geo.Coord.new()&lt;br /&gt;
&lt;br /&gt;
=== Distance calculations ===&lt;br /&gt;
&lt;br /&gt;
To calculate the distance between two points (in two different ways):&lt;br /&gt;
 # mylat1, mylong1, mylat2, mylong2 are lat &amp;amp; long in degrees &lt;br /&gt;
 # myalt1 &amp;amp; myalt2 are altitude in meters&lt;br /&gt;
 &lt;br /&gt;
 var GeoCoord1 = geo.Coord.new();&lt;br /&gt;
 GeoCoord1.set_latlon(mylat1, mylong1,myalt1);&lt;br /&gt;
 &lt;br /&gt;
 var GeoCoord2 = geo.Coord.new();&lt;br /&gt;
 GeoCoord2.set_latlon(mylat2, mylong2, myalt2);&lt;br /&gt;
 &lt;br /&gt;
 var directDistance = GeoCoord1.direct_distance_to(GeoCoord2);&lt;br /&gt;
 var surfaceDistance = GeoCoord1.distance_to(GeoCoord2);&lt;br /&gt;
&lt;br /&gt;
The results are distances in meters.&lt;br /&gt;
&lt;br /&gt;
* distance_to - returns distance in meters along Earth curvature, ignoring altitudes; useful for map distance&lt;br /&gt;
* direct_distance_to - returns distance in meters direct; considers altitude, but cuts through Earth surface&lt;br /&gt;
&lt;br /&gt;
=== Other useful geographical functions ===&lt;br /&gt;
Other useful geographical functions are found in geo.nas (in the FlightGear/data/Nasal directory of a FlightGear installation). geo.nas also includes documentation/explanation of the functions available.&lt;br /&gt;
&lt;br /&gt;
==Developing and debugging in Nasal==&lt;br /&gt;
===Developing Nasal code===&lt;br /&gt;
Because code in the Nasal directory is parsed only at Flightgear startup, testing and debugging Nasal code can by slow and difficult.&lt;br /&gt;
&lt;br /&gt;
Flightgear provides a couple of ways to work around this issue:&lt;br /&gt;
&lt;br /&gt;
====Nasal Console====&lt;br /&gt;
&lt;br /&gt;
The Nasal Console is available in Flightgear's menu (Debug/Nasal Console).  Selecting this menu opens a Nasal Console dialog.&lt;br /&gt;
&lt;br /&gt;
This dialog has several tabs, of which each can hold separate Nasal code snippets, all of which are saved on exit&lt;br /&gt;
and reloaded next time. This is useful for little tests, or for executing code for which writing a key binding is just too much&lt;br /&gt;
work, such as &amp;quot;props.dump(props.globals)&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
If you want to add more tabs (radio buttons in the Nasal Console dialog) to hold more code samples, just add more &amp;amp;lt;code&amp;amp;gt; nodes to autosave.xml.&lt;br /&gt;
&lt;br /&gt;
====Loading/reloading Nasal code without re-starting Flightgear====&lt;br /&gt;
A common problem in testing and debugging Nasal programs is that each testing step requires stopping and re-starting Flightgear, a slow process.&lt;br /&gt;
&lt;br /&gt;
Below is described a technique for loading and executing a Nasal file while Flightgear is running.  Flightgear will parse the file, display any errors in the Flightgear console window, and then execute the code as usual.&lt;br /&gt;
&lt;br /&gt;
Using this technique, you can start Flightgear, load the Nasal code you want to test observe any errors or test functionality as you wish, make changes to the Nasal file, reload it to observe parse errors or change in functionality, and so on to repeatedly and quickly run through the change/load/parse/test cycle without needing to re-start Flightgear each time.&lt;br /&gt;
&lt;br /&gt;
The key to this technique is the function io.load_nasal(), which loads a nasal file into a nasal namespace. &lt;br /&gt;
&lt;br /&gt;
Step-by-step instructions showing how to use this technique to load, parse, and test a Nasal file while Flightgear is running:&lt;br /&gt;
&lt;br /&gt;
=====Create the Nasal file to test=====&lt;br /&gt;
Create a text file named $FG_ROOT/foo/test.nas with this text:&lt;br /&gt;
  &lt;br /&gt;
  print(&amp;quot;hi!&amp;quot;);&lt;br /&gt;
  var msg=&amp;quot;My message.&amp;quot;;&lt;br /&gt;
  var hello = func { print(&amp;quot;I'm the test.hello() function&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
Notes: You can create the file in any directory you wish, as long as Nasal can read the directory--but the file IOrules in the Nasal directory restricts which directories Nasal may read and write from.  &lt;br /&gt;
&lt;br /&gt;
You can give the file any name and extension you wish, though it is generally most convenient to use the .nas extension with Nasal files.&lt;br /&gt;
&lt;br /&gt;
=====Load the file and test=====&lt;br /&gt;
Start Flightgear.  You can import the file above into Flightgear by typing the following into the Nasal Console dialog and executing the code:&lt;br /&gt;
&lt;br /&gt;
  io.load_nasal(getprop(&amp;quot;/sim/fg-root&amp;quot;) ~ &amp;quot;/foo/test.nas&amp;quot;, &amp;quot;example&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
getprop(&amp;quot;/sim/fg-root&amp;quot;) gets the root directory of the FlightGear installation, ~ &amp;quot;/foo/test.nas&amp;quot; appends the directory and filename you created.  The final variable &amp;quot;example&amp;quot; tells the namespace to load for the Nasal file.&lt;br /&gt;
&lt;br /&gt;
You'll see the message &amp;quot;hi!&amp;quot; on the terminal, and have function &amp;quot;example.hello()&amp;quot; immediately available. You can, for instance, type &amp;quot;example.hello();&amp;quot; into one of the Nasal console windows and press &amp;quot;Execute&amp;quot; to see the results; similarly you could execute &amp;quot;print (example.msg);&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
If you find errors or want to make changes, simply make them in your text editor, save the file, and execute the io.load_nasal() command again in the Nasal Console to re-load the file with changes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It's worth noting that Nasal code embedded in XML GUI dialog files can be reloaded by using the &amp;quot;debug&amp;quot; menu (&amp;quot;reload GUI&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
You may also want to check out the remarks on [[Nasal_scripting_language#Memory_management|Memory management]].&lt;br /&gt;
&lt;br /&gt;
==== Managing timers and listeners ====&lt;br /&gt;
&lt;br /&gt;
Note: If your Nasal program sets listeners, timer loops, and so on, they will remain set even when the code is reloaded, and reloading the code will set additional listeners and timer loops.  &lt;br /&gt;
&lt;br /&gt;
This can lead to extremely slow framerates and unexpected behavior.  For timers you can avoid this problem by using the loopid method (described above); for listeners you can create a function to destroy all timers your Nasal program creates, and call that function before reloading the program.  (And cleaning up timer loops and listeners is a best practice for creating Nasal programs in Flightgear regardless.)&lt;br /&gt;
&lt;br /&gt;
The same problem may occur while resetting or re-initializing parts of FlightGear if your code isn't prepared for this. And obviously this applies in particular also to any worker threads you may have started, too!&lt;br /&gt;
&lt;br /&gt;
For complex Nasal scripts with many timers and listeners, it is therefore generally a very good idea to implement special callbacks so that your scripts can respond to the most important simulator &amp;quot;signals&amp;quot;, this can be achieved by registering script-specific listeners to signals like &amp;quot;reinit&amp;quot; or &amp;quot;freeze&amp;quot; (pause): the corresponding callbacks can then suspend or re-initialize the Nasal code by suspending listeners and timers. Following this practice helps ensure that your code will behave properly even during simulator resets.&lt;br /&gt;
&lt;br /&gt;
In other words, it makes sense to provide a separate high-level controller routine to look for important simulator events and then pause or re-initialize your main Nasal code as required.&lt;br /&gt;
&lt;br /&gt;
If you are using [[Nasal_scripting_language#System-wide_Nasal_code|System-wide Nasal modules]], you should register listeners to properly re-initialize and clean up your Nasal code.&lt;br /&gt;
&lt;br /&gt;
In its simplest form, this could look like this:&lt;br /&gt;
&lt;br /&gt;
 var cleanup = func {}&lt;br /&gt;
 setlistener(&amp;quot;/sim/signals/reinit&amp;quot;, cleanup);&lt;br /&gt;
&lt;br /&gt;
This will invoke your &amp;quot;cleanup&amp;quot; function, whenever the &amp;quot;reinit&amp;quot; signal is set by the FlighGear core.&lt;br /&gt;
&lt;br /&gt;
Obviously, you now need to populare your cleanup function with some code, too.&lt;br /&gt;
&lt;br /&gt;
One of the easiest ways to do this, is removing all listeners/timers manually here, i.e. by adding calls to removelistener():&lt;br /&gt;
&lt;br /&gt;
 var cleanup = func {&lt;br /&gt;
  removelistener(id);&lt;br /&gt;
  removelistener(id);&lt;br /&gt;
  removelistener(id);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This would ensure that the corresponding listeners would be removed once the signal is triggered.&lt;br /&gt;
&lt;br /&gt;
On the other hand, you could just as well use a vector of listener IDs here, and then use a Nasal foreach loop:&lt;br /&gt;
&lt;br /&gt;
 var cleanup = func(id_list) {&lt;br /&gt;
  foreach(var id; id_list)&lt;br /&gt;
   removelistener(id);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Obviously, this would require that you maintain a list of active listeners, too - so that you can actually pass a list of IDs to the cleanup function.&lt;br /&gt;
&lt;br /&gt;
This is one of those things that can be easily done in Nasal, too - just by introducing a little helper wrapper:&lt;br /&gt;
&lt;br /&gt;
 var id_list=[];&lt;br /&gt;
 var store_listener = func(id) append(id_list,id);&lt;br /&gt;
&lt;br /&gt;
The only thing required here, would be replacing/wrapping the conventional &amp;quot;setlistener&amp;quot; call with calls to your helper:&lt;br /&gt;
&lt;br /&gt;
 store_listener( setlistener(&amp;quot;/sim/foo&amp;quot;) );&lt;br /&gt;
 store_listener( setlistener(&amp;quot;/foo/bar&amp;quot;) );&lt;br /&gt;
&lt;br /&gt;
If you were to do this consistently across all your Nasal code, you'd end up with a high level way to manage all your registered listeners centrally.&lt;br /&gt;
&lt;br /&gt;
Now, you'll probably have noticed that it would make sense to consider wrapping all these helpers and variables inside an enclosing helper class, this can be accomplished in Nasal using a hash. This would enable you to to implement everything neatly organized in an object and use RAII-like patterns to manage Nasal resources like timers, listeners and even threads.&lt;br /&gt;
&lt;br /&gt;
===Debugging===&lt;br /&gt;
The file debug.nas, included in the Nasal directory of the Flightgear distribution, has several functions useful for debugging Nasal code.  These functions are available to any Nasal program or code executed by Flightgear.&lt;br /&gt;
&lt;br /&gt;
Aside from those listed below, several other useful debugging functions are found in debug.nas; see the debug.nas file for the list of functions and explanation.&lt;br /&gt;
&lt;br /&gt;
Note that the debug module makes extensive use of ANSI terminal color codes.  These create colored output on Linux/Unix systems but on other systems they may add numerous visible control codes.  To turn off the color codes, go to the internal property tree and set&lt;br /&gt;
&lt;br /&gt;
 /sim/startup/terminal-ansi-colors=0&lt;br /&gt;
&lt;br /&gt;
Or within a Nasal program:&lt;br /&gt;
&lt;br /&gt;
 setprop (&amp;quot;/sim/startup/terminal-ansi-colors&amp;quot;,0);&lt;br /&gt;
&lt;br /&gt;
====debug.dump====&lt;br /&gt;
 debug.dump([&amp;lt;variable&amp;gt;])             ... dumps full contents of variable or of local variables if none given&lt;br /&gt;
 &lt;br /&gt;
The function debug.dump() dumps the contents of the given variable to the console. On Unix/Linux this is done with some syntax coloring. For example, these lines&lt;br /&gt;
&lt;br /&gt;
  var as = props.globals.getNode(&amp;quot;/velocities/airspeed-kt&amp;quot;, 1);&lt;br /&gt;
  debug.dump(as);&lt;br /&gt;
&lt;br /&gt;
would output&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/velocities/airspeed-kt=1.021376474393101 (DOUBLE; T)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;T&amp;quot; means that it's a &amp;quot;tied&amp;quot; property. The same letters are used here as in the property-browser. The angle brackets seem superfluous, but are useful because debug.dump() also outputs compound data types, such as vectors and hashes. For example:&lt;br /&gt;
&lt;br /&gt;
  var as = props.globals.getNode(&amp;quot;/velocities/airspeed-kt&amp;quot;, 1);&lt;br /&gt;
  var ac = props.globals.getNode(&amp;quot;/sim/aircraft&amp;quot;, 1);&lt;br /&gt;
  var nodes = [as, ac];&lt;br /&gt;
  var hash = { airspeed_node: as, aircraft_name: ac, all_nodes: nodes };&lt;br /&gt;
  debug.dump(hash);&lt;br /&gt;
&lt;br /&gt;
yields:&lt;br /&gt;
&lt;br /&gt;
  { all_nodes : [ &amp;lt;/velocities/airspeed-kt=1.021376474393101 (DOUBLE; T)&amp;gt;,&lt;br /&gt;
  &amp;lt;/sim/aircraft=&amp;quot;bo105&amp;quot; (STRING)&amp;gt; ], airspeed_node : &amp;lt;/velocities/airspe&lt;br /&gt;
  ed-kt=1.021376474393101 (DOUBLE; T)&amp;gt;, aircraft_name : &amp;lt;/sim/aircraft=&amp;quot;bo&lt;br /&gt;
  105&amp;quot; (STRING)&amp;gt; }&lt;br /&gt;
&lt;br /&gt;
====debug.backtrace====&lt;br /&gt;
  debug.backtrace([&amp;lt;comment:string&amp;gt;]}  ... writes backtrace with local variables&lt;br /&gt;
  debug.bt                             ... abbreviation for debug.backtrace&lt;br /&gt;
&lt;br /&gt;
The function debug.backtrace() outputs all local variables of the current function and all parent functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====debug.benchmark====&lt;br /&gt;
debug.benchmark(&amp;lt;label:string&amp;gt;, &amp;lt;func&amp;gt; [, &amp;lt;repeat:int&amp;gt;])&lt;br /&gt;
 ... runs function &amp;lt;repeat&amp;gt; times (default: 1) and prints execution time in seconds,prefixed with &amp;lt;label&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This is extremely useful for benchmarking pieces of code to determin &lt;br /&gt;
====debug.exit====&lt;br /&gt;
  debug.exit()                         ... exits fgfs&lt;br /&gt;
&lt;br /&gt;
== Related content ==&lt;br /&gt;
{{Forum|30|Nasal}}&lt;br /&gt;
* [[:Category:Nasal]]&lt;br /&gt;
&lt;br /&gt;
=== External links ===&lt;br /&gt;
* http://www.plausible.org/nasal&lt;br /&gt;
&lt;br /&gt;
[[Category:Nasal]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Howto:Carrier&amp;diff=38059</id>
		<title>Howto:Carrier</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Howto:Carrier&amp;diff=38059"/>
		<updated>2011-12-18T07:27:49Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* From commandline */ typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Over the years, [[FlightGear]] has been equipped with a vast amount of [[aircraft carrier]]s that allow pilots to simulate the entire range of carrier operations, from catapult takeoffs, to &amp;quot;controlled crashes&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==Features==&lt;br /&gt;
[[File:Carrier3.jpg|thumb|300px|The Nimitz carrier in the San Fransisco bay]]&lt;br /&gt;
&lt;br /&gt;
* Start FG with your chosen aircraft placed on the aircraft carrier &amp;quot;Nimitz&amp;quot; or &amp;quot;Eisenhower&amp;quot;&lt;br /&gt;
* Engage the launchbar in the steam catapult&lt;br /&gt;
* Have the carrier set course into the prevailing wind direction and attempt to get wind speed over the deck at a suitable value for launch&lt;br /&gt;
* Launch from the deck when ready&lt;br /&gt;
* Set the TACAN receiver in the aircraft to Nimitz's channel (029Y) and have the heading and range to the carrier displayed on the cockpit instruments&lt;br /&gt;
* Land on the deck and be halted by the arrestor cables&lt;br /&gt;
* Taxi onto the deck elevators, operate them and park on the hangar deck (0.9.10 and later)&lt;br /&gt;
&lt;br /&gt;
== Start at a carrier ==&lt;br /&gt;
Note that several FlightGear aircraft are carrier capable, but the [[Hawker Seahawk|Seahawk]] is possibly the easiest to fly to begin with. You can start FlightGear with the command line or a GUI.&lt;br /&gt;
&lt;br /&gt;
=== From commandline ===&lt;br /&gt;
To position your [[aircraft]] on the carrier at startup, use the following [[Command Line Parameters|command line options]] beside your normal options ([[$FG_ROOT|fg-root]] etc.). Note the upper-case &amp;quot;N&amp;quot; in Nimitz and the fact that the scenario comes in front of carrier! You can copy-paste this (the slash will make it look like one line):&lt;br /&gt;
 --ai-scenario=nimitz_demo \&lt;br /&gt;
 --carrier=Nimitz \&lt;br /&gt;
 --aircraft=seahawk \&lt;br /&gt;
&lt;br /&gt;
Please note the uppercase N in &amp;lt;tt&amp;gt;--carrier=Nimitz&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The following (optional) start positions are available:&lt;br /&gt;
 --parkpos=cat-1&lt;br /&gt;
 --parkpos=cat-2&lt;br /&gt;
 --parkpos=cat-3&lt;br /&gt;
 --parkpos=cat-4&lt;br /&gt;
 --parkpos=park-1&lt;br /&gt;
&lt;br /&gt;
=== Mac OS X launcher ===&lt;br /&gt;
If you are using the OSX launcher to run FlightGear, you should find a text entry box in the gui that allows you to specify command line options, add the above mentioned commands there.&lt;br /&gt;
&lt;br /&gt;
=== Windows launcher ===&lt;br /&gt;
As of FlightGear 1.0.0 there comes a special box for the carriers on the airport selection page of the wizard. Type &amp;lt;tt&amp;gt;Nimitz&amp;lt;/tt&amp;gt; in the carrier box and select &amp;lt;tt&amp;gt;nimitz_demo&amp;lt;/tt&amp;gt; in the scenario list on the next page.&lt;br /&gt;
&lt;br /&gt;
== Takeoff ==&lt;br /&gt;
[[File:Carrier1.jpg|thumb|300px|The [[Hawker Seahawk|Seahawk]] aircraft ready for takeoff]]&lt;br /&gt;
Once FlightGear has started, you should ensure that the parking brakes are off, ease the plane a little way down the catapult pressing L to engage the launchbar (hold for several seconds until given &amp;quot;Engaged&amp;quot; feedback; this might be best done from an external view initially.) You should notice the aircraft being pulled into alignment with the catapult and see the strops appear and hold down the aircraft. This will only happen if your aircraft is close enough to the correct spot on the catapult; as a rough guide, for the default parking position the seahawk's nose should be rougly level with the deck observation bubble.&lt;br /&gt;
&lt;br /&gt;
To get the carrier into as good a position as possible for launch, select the &amp;lt;tt&amp;gt;AI &amp;gt; Carrier Controls&amp;lt;/tt&amp;gt; menu, then check the &amp;quot;Turn to launch course&amp;quot; box.&lt;br /&gt;
&lt;br /&gt;
You should now notice the carrier begin to pick up speed and turn into the wind, and naturally the deck may tilt somewhat as it turns. You should wait for this maneuver to finish and the deck to return to level before moving on to the next stage.&lt;br /&gt;
[[Image:Carrier6.jpg|thumb|300px|'''1:''' The takeoff part of the carrier with the catapults &lt;br /&gt;
'''2:''' The land part of the carrier with the wires]]&lt;br /&gt;
Being engaged to the catapult, you should spool up the engines to full power, ensure the brakes are off and that all flight controls are in a suitable position for launch. When ready, press C to release the catapult. Your aircraft will be hurled forward off the deck, and you should be able to raise the undercarriage and climb slowly away, being careful to avoid stalling.&lt;br /&gt;
&lt;br /&gt;
== Locating the carrier ==&lt;br /&gt;
Actually finding the carrier in a vast expanse of open water can be very difficult, especially if visibility is poor. To assist with this task, the carriers are equipped with [[TACAN]], which allows a suitably-equipped aircraft (Seahawk at present) to obtain a range and bearing to the carrier.&lt;br /&gt;
&lt;br /&gt;
First, you must set the appropriate TACAN channel, 029Y in this case, in the radios dialogue (Ctrl-R or choose &amp;lt;tt&amp;gt;Equipment &amp;gt; Radio Settings&amp;lt;/tt&amp;gt; from the menu). You should, if within range, notice the [[DME]] instrument show your distance from the carrier, and the [[ADF]] instrument (next to the DME in the seahawk) should indicate a bearing to the carrier. Turn to the indicated heading and you should see the DME dial indicate you're closing in on the carrier.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
! Carrier || Scenario || TACAN&lt;br /&gt;
|-&lt;br /&gt;
| Nimitz || nimitz_demo || 029Y&lt;br /&gt;
|-&lt;br /&gt;
| Eisenhower || nimitz_demo || 030Y&lt;br /&gt;
|-&lt;br /&gt;
| Clemenceau || clemenceau_demo || 026Y&lt;br /&gt;
|-&lt;br /&gt;
| Foch || foch_demo || 026X&lt;br /&gt;
|-&lt;br /&gt;
| Akagi || akagi || N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Landing ==&lt;br /&gt;
This is the most difficult part of the operation, as in real life. You might well find Andy Ross' [[A-4F Skyhawk Operations Manual]] useful here.&lt;br /&gt;
&lt;br /&gt;
Basically, though, you should use the TACAN to locate the carrier, and line up with the rear of the deck. As this part of the deck is at an angle to the course of the vessel, you may need to correct your alignment often. Ensure that the aircraft is in the correct configuration for approach (the &amp;lt;tt&amp;gt;Help &amp;gt; Aircraft Help&amp;lt;/tt&amp;gt; menu should contain useful data for your aircraft) and that the gear and the arrestor hook are down.&lt;br /&gt;
&lt;br /&gt;
[[File:Carrier5.jpg|thumb|300px|The Fresnel Lens Optical landing System]]&lt;br /&gt;
As you approach you should see, on the left hand side of the deck, a set of brightly coloured lights - called the Fresnel Lens Optical landing System (FLOLS). This indicates your position on the landing glideslope. You will see a horizontal row of green lights, and when approximately on the glideslope, an orange light ( known in some circles as 'the meatball') approximately in line with the green lights. When approaching correctly, the meatball appears in line with the green lights. If you are high it is above, and when low it is below. If you are very low the meatball turns red. If you fly to keep the meatball aligned you should catch number 3 wire.&lt;br /&gt;
&lt;br /&gt;
=== Touchdown ===&lt;br /&gt;
Carrier landings are often described as &amp;quot;controlled crashes&amp;quot; and you shouldn't waste your time attempting to flare and place the aircraft gently on the deck like you would with a conventional landing - ensuring that you catch the wires is the main thing.&lt;br /&gt;
&lt;br /&gt;
Immediately your wheels touch the deck, you should open the throttles to full power, in case you have missed the wires and need to go around again; the wires will hold the aircraft if you have caught them, even at full power.&lt;br /&gt;
&lt;br /&gt;
If you wish, you can then (with 0.9.10 and later) raise the elevators from the carrier menu, taxi onto one of the elevators, lower it (uncheck the box on the menu and don't worry, they are VERY slow...) and taxi off into the hangar.&lt;br /&gt;
&lt;br /&gt;
Don't be discouraged if you don't succeed at first with carrier landings - it's not an easy maneouver to master. If after a little practice you find the Seahawk too easy, you could move on to the Seafire for more of a challenge!&lt;br /&gt;
&lt;br /&gt;
== Related content ==&lt;br /&gt;
* [[Carrier over MP]] to find out how you could control the carrier and/or use the carrier over the multiplayer network.&lt;br /&gt;
&lt;br /&gt;
[[de:Flugzeugträger]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Howto|Carrier]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Aircraft&amp;diff=37927</id>
		<title>Aircraft</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Aircraft&amp;diff=37927"/>
		<updated>2011-12-15T08:08:18Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Spacecrafts */ improve sentence&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This list is not updated to include all the official [[GNU General Public License|GPL licensed]] '''aircraft''' for [[FlightGear]], but gives a visual sampling of the different types of aircraft and genres of aircraft officially available. See [[Table of models]] for the comprehensive list.&lt;br /&gt;
&lt;br /&gt;
The examples listed here are officially available from the FlightGear project, and can be downloaded at [http://flightgear.org/Downloads/aircraft-2.0.0/ FlightGear.org], with installation typically requiring an unzipping program, and manual [[Howto: Install aircraft|installation]] in the FlightGear aircraft directory. More aircraft are available in [[FlightGear hangars|non-official hangars]].&lt;br /&gt;
&lt;br /&gt;
FlightGear aircraft features, quality, and compatibility vary significantly. Their development is dependent on the [[volunteer]]s who worked on them, with exception of some University and Government funded projects.&lt;br /&gt;
&lt;br /&gt;
=== Light civilian aircraft ===&lt;br /&gt;
The Cessna 172 is the default aircraft in FGFS 2.0. These aircraft typically have 1-2 piston engines, props, and avionics geared towards those with civilian pilot licenses.&lt;br /&gt;
{{Gallery|&lt;br /&gt;
[[Aerostar 700]]|Aerostar_700.jpg|&lt;br /&gt;
[[B&amp;amp;F FK9 Mark 2]]|FK9MK2.jpg|&lt;br /&gt;
[[Cessna C172|Cessna 172P]] (1982)|Cessna_172P.jpg|&lt;br /&gt;
[[Piper Cherokee Warrior II|Piper Cherokee Warrior II (PA28-161)]]|Piper_Cherokee_Warrior_II.png|&lt;br /&gt;
[[Piper PA-24 Comanche|Piper Comanche (PA24-250)]]|Pa-24.jpg|&lt;br /&gt;
[[Piper J3 Cub]] (1946) |Piper_j3cub.jpg|&lt;br /&gt;
[[Piper PA34-200T Seneca II|Piper Seneca II (PA34-200T)]]|Piper_SenecaII.jpg|&lt;br /&gt;
[[Robin DR400]]|dr400.jpg|&lt;br /&gt;
[[Rallye-MS893E]]|Rallye-MS893.jpg&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Modern Airliners ===&lt;br /&gt;
These typically have 2-4 turbofan engines and some of the more complicated takeoff and landing procedures (such as multiple [[flaps]]). In addition, avionics in real life is geared towards those with professional pilots licenses and special certifications. However, the simplifications of FG make it much easier to fly in the simulation.&lt;br /&gt;
&lt;br /&gt;
==== Narrowbody &amp;amp; Midsize ====&lt;br /&gt;
{{Gallery|&lt;br /&gt;
[[Airbus A320 Family]]|A320-family.jpg|&lt;br /&gt;
[[Beechcraft B1900D]]|Beechcraft B1900D.png|&lt;br /&gt;
[[Bombardier CRJ-200LR]]|Picture 11.png|&lt;br /&gt;
[[Bombardier CRJ700 series]]|CRJ700.jpg|&lt;br /&gt;
[[Boeing 757]]|757-2002.jpg|&lt;br /&gt;
[[Boeing 707]]|707.jpg|&lt;br /&gt;
[[Boeing 717]]|717-200.jpg|&lt;br /&gt;
[[Boeing 737-100]]|737-100.png|&lt;br /&gt;
[[Boeing 737-300]]|737-300.jpg|&lt;br /&gt;
[[Boeing 727-230]]|727-230.2.jpeg|&lt;br /&gt;
[[Concorde]]|Concorde.png&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==== Widebody &amp;amp; Jumbo Airliners ====&lt;br /&gt;
{{Gallery|&lt;br /&gt;
[[Airbus A340-600]]|Airbus.png|&lt;br /&gt;
[[Airbus A380]]|A380.jpg|&lt;br /&gt;
[[Boeing 777-200]]|777-200.jpg|&lt;br /&gt;
[[Boeing 767-300]]|Shadow.png|&lt;br /&gt;
[[Boeing 747-400]]|747-400.jpg|&lt;br /&gt;
[[Boeing 787]]|787.png|&lt;br /&gt;
[[Airbus A350]]|A350.png|&lt;br /&gt;
[[IL-96-400 Long Ranger(T)]]|1z5hr43.bmp&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Helicopters ===&lt;br /&gt;
{{Main article|Helicopter}}&lt;br /&gt;
&lt;br /&gt;
Helicopters have fundamentally different controls than fixed wing aircraft (see ''[[Flying the Helicopter]]''). Modern helicopter typically feature 1-2 turbine engines, which power a main rotor with 2-6 blades.&lt;br /&gt;
{{Gallery|&lt;br /&gt;
[[AH-1 Cobra]]|Ah-1_vietnam_firebase.png|&lt;br /&gt;
[[Eurocopter Bo105|MBB Bo 105]]|FlightGearNL-9.jpg|&lt;br /&gt;
[[Eurocopter EC135|Eurocopter EC-135]]|Ec135.png|&lt;br /&gt;
[[CH-47 Chinook Helicopter|Boeing CH-47 Chinook]]|CH-47_Chinook.jpg|&lt;br /&gt;
[[Hughes OH-6 Cayuse]]|OH-6.png|&lt;br /&gt;
[[Sikorsky S58|Sikorsky S-58]]|S58.jpg&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Gliders, Sailplanes, &amp;amp; Ultralights ===&lt;br /&gt;
These typically have the simplest controls, with minimal avionics. Flying [[:Category:Gliders|gliders]] or sailplanes using [[Soaring|thermals]] can provide more complicated experience. Ultralights on the other hand are among the simplest aircraft in FG.&lt;br /&gt;
{{Gallery|&lt;br /&gt;
[[Airwave Xtreme 150]]|AirwaveXtreme150.jpg|&lt;br /&gt;
[[Dragonfly|Moyes Dragonfly]]|Dragonfly-towing.jpg|&lt;br /&gt;
[[Paraglider]]|Paraglider.jpg|&lt;br /&gt;
[[GDT Hornet (autogyro)]]|Hornet.jpg|&lt;br /&gt;
[[Schweizer 2-33]]|Sgs233.jpg|&lt;br /&gt;
[[ASW-20 sailplane|Schleicher ASW-20]]|Asw20.jpg|&lt;br /&gt;
[[Glaser-Dirks DG-300]]|DG-300.jpg|&lt;br /&gt;
[[Glaser-Dirks_DG-101G]]|DG-101G_001.jpg&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Warbirds ===&lt;br /&gt;
FlightGear includes a wide variety of vintage military aircraft. Complexity and realism is typically tied to the level of development work with a specific aircraft.&lt;br /&gt;
{{Gallery|&lt;br /&gt;
[[Bristol Beaufighter]]|Beaufighter.png|&lt;br /&gt;
[[Fokker Dr.I]]|Fokker_DrI.jpg|&lt;br /&gt;
[[P-51D Mustang]]|P51d-mustang.png|&lt;br /&gt;
[[A6M2 Zero‎]]|A6M2.gif|&lt;br /&gt;
[[Nakajima Ki-84‎]]|ki-84.jpg|&lt;br /&gt;
[[Focke-Wulf Fw 190]]|Fw190.jpg|&lt;br /&gt;
[[Sopwith Camel]]|Sopwith_Camel.png|&lt;br /&gt;
[[Supermarine Spitfire]]|Spitfire.jpg|&lt;br /&gt;
[[MiG-15]]|MiG-15bis-Exterior.jpg|&lt;br /&gt;
[[IAR 80]]|iar80-angry.jpg|&lt;br /&gt;
[[F4U Corsair]]|F4u-park.jpg|&lt;br /&gt;
[[Messerschmitt Bf 109]]|109-1.png&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Carrier-borne aircraft ===&lt;br /&gt;
FlightGear supports landing on and taking off from [[carriers]].&lt;br /&gt;
&lt;br /&gt;
{{Gallery|&lt;br /&gt;
[[Grumman A-6E|Grumman A-6E Intruder]]|A-6E.jpg|&lt;br /&gt;
[[Blackburn Buccaneer]]|Buccaneer.jpg|&lt;br /&gt;
[[Grumman F-14 Tomcat]]|F-14.jpg|&lt;br /&gt;
[[Hawker Seahawk|Hawker Seahawk FGA6]]|Hawker_Seahawk.jpg&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Modern military aircraft ===&lt;br /&gt;
FlightGear has a wide variety of modern and retired military jets available, highlighted by features such as air-to-air refueling from the venerable KC-135 and the ability to simulate A-10 ordnance release.&lt;br /&gt;
&lt;br /&gt;
{{Gallery|&lt;br /&gt;
[[Fairchild A-10]]|A-10.jpg|&lt;br /&gt;
[[Boeing B-52]]|B-52F.jpg|&lt;br /&gt;
[[Boeing E-3 Sentry]]|E-3B.jpg|&lt;br /&gt;
[[F-15C Eagle]]|F-15C.jpg|&lt;br /&gt;
[[British Aerospace Harrier]]|Harrier.jpg|&lt;br /&gt;
[[General Dynamics F-16]]|General_Dynamics_F16.jpg|&lt;br /&gt;
[[Cessna T-37]]|Cessna T-37.jpg|&lt;br /&gt;
[[Northrop T-38]]|Northrop_T-38.jpg|&lt;br /&gt;
[[North American OV-10A Bronco]]|OV-10A2.jpg|&lt;br /&gt;
[[Saab J 35Ã– Draken|Saab J35Ö Draken]]|Saab_J35.jpg|&lt;br /&gt;
[[HAL Tejas]]|LCA.jpeg|&lt;br /&gt;
[[Lockheed Martin F-22 Raptor]]|F-22.png&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Historical ===&lt;br /&gt;
Many obscure to famous older aircraft of varying quality are available.&lt;br /&gt;
{{Gallery|&lt;br /&gt;
[[Couzinet 70]]|Couzinet70.jpg|&lt;br /&gt;
[[De Havilland D.H. 91 Albatross]]|dh91.jpg|&lt;br /&gt;
[[Douglas DC-3]]|Douglas_DC3.jpg|&lt;br /&gt;
[[ComperSwift Comper]]|ComperSwift.jpg|&lt;br /&gt;
[[Lockheed 1049|Lockheed Constellation]]|Lockheed_1049.jpg|&lt;br /&gt;
[[Boeing 314]]|314.jpg|&lt;br /&gt;
[[de Havilland Canada DHC-3 Otter]]|DHC-3.jpg|&lt;br /&gt;
[[Wright Flyer (UIUC)]]|1903_Wright_Flyer.jpg|&lt;br /&gt;
[[Short Empire]]|Short_Empire.jpg&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Experimental &amp;amp; Unique ===&lt;br /&gt;
Experimental and special purpose aircraft. &lt;br /&gt;
{{Gallery|&lt;br /&gt;
[[BAC TSR-2 Prototype]]|BAC_TSR-2_Prototype.jpg|&lt;br /&gt;
[[Bell Boeing V22 Osprey|Bell V-22 Osprey]]|V22Osprey.jpg|&lt;br /&gt;
[[North American X-15]]|X15.jpg|&lt;br /&gt;
[[Northrop/McDonnell Douglas YF-23]]|YF-23.jpg&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Lighter than air aircraft (Available from version 1.9.0) ===&lt;br /&gt;
These aircraft take advantage of lighter than air gas to become buoyant. In addition to typical aircraft control methods such as elevator, rudder and engine throttle, ballast and control of gas volume and pressure become options.&lt;br /&gt;
&lt;br /&gt;
{{Gallery|&lt;br /&gt;
[[Zeppelin NT]]|Zeppelin_NT.jpg|&lt;br /&gt;
[[ZF Navy free balloon]]|ZF_Navy_free_balloon.jpg|&lt;br /&gt;
[[Submarine Scout]]|Submarine_Scout.jpg|&lt;br /&gt;
[[Zeppelin LZ 121 Nordstern]]|Zeppelin_LZ_121_Nordstern.jpg&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Science Fiction ===&lt;br /&gt;
Alternative models provide a diversion of realistic simulation, but can also be useful for exploring scenery.&lt;br /&gt;
{{Gallery|&lt;br /&gt;
[[UFO from the 'White Project' of the UNESCO]]|UFO.jpg|&lt;br /&gt;
[[Bluebird]]|bluebird_hovercraft.jpg&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Spacecrafts ===&lt;br /&gt;
Things that show how small our planet Earth really is.&lt;br /&gt;
{{Gallery|&lt;br /&gt;
[[Vostok-1]]|Vostok-1-Thumbnail.jpg&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Page settings after this --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[de:Flugzeuge]]&lt;br /&gt;
[[es:Avión]]&lt;br /&gt;
[[nl:Luchtvaartuigen]]&lt;br /&gt;
[[fr:Avions]]&lt;br /&gt;
[[pt:Avião]]&lt;br /&gt;
&lt;br /&gt;
[[Category:List]]&lt;br /&gt;
[[Category:Aircraft]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Building_FlightGear_-_Linux&amp;diff=37796</id>
		<title>Building FlightGear - Linux</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Building_FlightGear_-_Linux&amp;diff=37796"/>
		<updated>2011-12-11T02:41:53Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* APT-GET List */ typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Main article|Building Flightgear}} &lt;br /&gt;
&lt;br /&gt;
This section describes how to build [[FlightGear]] on Linux system.&lt;br /&gt;
&lt;br /&gt;
Compiling FlightGear is not a task for novice users. Thus, if you're a beginner (we all were once) on a platform which binaries are available for, we recommend postponing this task and just starting with the binary distribution to get you flying.&lt;br /&gt;
&lt;br /&gt;
Or if you develop on Ubuntu or Debian, consider trying the script described in [[Scripted Compilation on Linux Debian/Ubuntu]].&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
Before you can compile FlightGear, you need to have the following installed on your computer:&lt;br /&gt;
&lt;br /&gt;
'''C++ compiler'''&lt;br /&gt;
&lt;br /&gt;
These are: c++, cpp, gcc, g++ found under the /usr/bin directory.  You will also need to have the tools '''autoconf''' and '''automake1.9''' installed.&lt;br /&gt;
&lt;br /&gt;
'''GIT'''&lt;br /&gt;
&lt;br /&gt;
See [[FlightGear and Git]].&lt;br /&gt;
&lt;br /&gt;
'''[[OpenGL]] support'''&lt;br /&gt;
&lt;br /&gt;
More specifically, your system needs the support for hardware accelerated graphics.  You can check for this by running the following in a [[command line]]:&lt;br /&gt;
&lt;br /&gt;
 glxinfo | grep direct&lt;br /&gt;
&lt;br /&gt;
Note: To run the above command, you need to have the tool '''mesa-utils''' installed.&lt;br /&gt;
&lt;br /&gt;
You should then see:&lt;br /&gt;
&lt;br /&gt;
 direct rendering: Yes&lt;br /&gt;
&lt;br /&gt;
This means you are good to go as far as OpenGL support is concerned.&lt;br /&gt;
&lt;br /&gt;
If you see:&lt;br /&gt;
&lt;br /&gt;
 direct rendering: No&lt;br /&gt;
&lt;br /&gt;
Don't panic yet.  This may just mean some required libraries for hardware accelerated graphic are missing.  Go ahead and try installing plib 1.8.5 and its dependencies first.  If you still get the above message, then you will need to do some googling and troubleshoot yourself.&lt;br /&gt;
&lt;br /&gt;
== Dependencies ==&lt;br /&gt;
FlightGear is dependent on quite a few number of libraries.  You do not need to compile all of them yourself, but you will at least need to have their development version installed.  For example, the development version for package plib1.8.5 is plib1.8.5'''-dev'''.&lt;br /&gt;
&lt;br /&gt;
The dependency is summarized in the following tree.  Please note that each library has its own dependencies, and most of these are not shown here.&lt;br /&gt;
&lt;br /&gt;
* FlightGear&lt;br /&gt;
** [http://kcat.strangesoft.net/openal.html OpenAL]&lt;br /&gt;
** SimGear&lt;br /&gt;
*** [http://plib.sourceforge.net/ PLIB]. Since March 2008, you will need version 1.8.5 - your distro probably supplies 1.8.4 still.&lt;br /&gt;
**** For versions pre March 2008: (Free)GLUT or SDL (We recommend the use of SDL over Free/GLUT, [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg16153.html however since March 2008, FreeGLUT as well as SDL are both considered depreciated, please only use --enable-osgviewer during configuration instead]) &lt;br /&gt;
***  [[OpenSceneGraph]]  (check link for compatible versions)&lt;br /&gt;
*** You also need the development files for several basic libraries to build the software, among them the following (the package names are for Debian and derivatives(?)):&lt;br /&gt;
**** libfreetype6-dev&lt;br /&gt;
**** libjpeg62-dev&lt;br /&gt;
**** libungif4-dev&lt;br /&gt;
**** libtiff4-dev&lt;br /&gt;
**** libpng12-dev&lt;br /&gt;
**** libxmu-dev&lt;br /&gt;
**** libxi-dev&lt;br /&gt;
**** zlib1g-dev&lt;br /&gt;
**** libglut3-dev&lt;br /&gt;
&lt;br /&gt;
If you attack the above dependencies in the order listed below, you should be good:&lt;br /&gt;
&lt;br /&gt;
1. Glut. Most distributions include glut packages, although you may have to hunt for them. Make sure you install both the glut and glut-devel packages, otherwise FlightGear may be able to compile but won't run correctly.&lt;br /&gt;
&lt;br /&gt;
2. Zlib. Most distributions install the basic zlib libraries by default, but not the development portions. If you don't have zlib.h, you probably need to install the zlib-devel package for your distribution. &lt;br /&gt;
&lt;br /&gt;
3. Plib - portability libraries and scene graph. &lt;br /&gt;
&lt;br /&gt;
4.  [[OpenSceneGraph]] &lt;br /&gt;
&lt;br /&gt;
5. SimGear - Simulation support libraries. If you are building FlightGear from Git, you need the Git version of SimGear. If you have strange build errors, one of the first things to check is that you have an up-to-date version of SimGear built and installed.&lt;br /&gt;
&lt;br /&gt;
==== APT-GET List ====&lt;br /&gt;
This is a list of all the apt-get commands I had to do while compiling FG, SG, and OSG on a mostly clean Ubuntu 64 system. It is a list of all the libraries you and your computer needs to compile FG, SG, OSG, and PLib. All you have to do is copy the full command, paste it in Terminal, enter your password, and it will download all the packages for you, and install them too. The full command is at the bottom, and I hope someone finds it useful :) sub-dependencies (dependencies of the dependencies) are not included as they are installed automatically by apt-get. If anyone sees something missing, please add it.&lt;br /&gt;
 &lt;br /&gt;
git - to get SG and FG&amp;lt;br /&amp;gt;&lt;br /&gt;
subversion - to get OSG&amp;lt;br /&amp;gt;&lt;br /&gt;
build-essential - to build (includes GCC, and other build tools)&amp;lt;br /&amp;gt;&lt;br /&gt;
cmake - OSG Uses this&amp;lt;br /&amp;gt;&lt;br /&gt;
cmake-curses-gui -- OSG Uses this&amp;lt;br /&amp;gt;&lt;br /&gt;
libpng-dev - to enable FG to use PNG textures&amp;lt;br /&amp;gt;&lt;br /&gt;
libfreetype6-dev - fonts&amp;lt;br /&amp;gt;&lt;br /&gt;
libjpeg-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libungif4-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libtiff-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libxmu-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libxi-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libglut3-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libalut-dev - sound&amp;lt;br /&amp;gt;&lt;br /&gt;
libboost-dev - makes coding for some developers easier&amp;lt;br /&amp;gt;&lt;br /&gt;
''automake - needed by ./autogen.sh files''&amp;lt;br /&amp;gt;&lt;br /&gt;
''autoconf - needed by ./autogen.sh files''&amp;lt;br /&amp;gt;&lt;br /&gt;
libfltk1.1-dev - You will need this if you will be using FGRun&amp;lt;br /&amp;gt;&lt;br /&gt;
-----------&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install git subversion build-essential cmake cmake-curses-gui libpng-dev libfreetype6-dev&lt;br /&gt;
libjpeg-dev libungif4-dev libtiff-dev libxmu-dev libxi-dev libglut3-dev libalut-dev&lt;br /&gt;
libboost-dev automake autoconf libfltk1.1-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
-----------&lt;br /&gt;
Total size is about 230 MB, depending on what you already have from other applications.&lt;br /&gt;
&lt;br /&gt;
This list might seem a bit short, but the sub-dependencies all add up :) The dependencies will be listed by apt-get when you use the command.&lt;br /&gt;
-----------&lt;br /&gt;
NOTE: On a Linux Mint 9 (Ubuntu 10.04) system this is the command I used:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install git-core subversion build-essential cmake cmake-curses-gui libpng-dev libfreetype6-dev libjpeg-dev libungif4-dev&lt;br /&gt;
libtiff-dev libxmu-dev libxi-dev libglut3-dev libalut-dev libboost-dev ''automake autoconf'' libfltk1.1-dev libplib-dev libopenscenegraph-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
libopenscenegraph-dev&lt;br /&gt;
You just need to copy that long line into a terminal and you should have all the packages you need to compile Flightgear and Simgear.&lt;br /&gt;
&lt;br /&gt;
== Compiling ==&lt;br /&gt;
Assuming you are root, do:&lt;br /&gt;
 cd /usr/local/src&lt;br /&gt;
&lt;br /&gt;
'''Note:''' When tracking a fast changing software like FlightGear/Git it is highly advisable to install it in a separate directory. That way one can also easily build and reinstall without being root, which greatly reduces the risk of messing up one's system.&lt;br /&gt;
To install in a directory of your choice add the &amp;lt;tt&amp;gt;--prefix&amp;lt;/tt&amp;gt; argument to configure. E.g. &amp;lt;tt&amp;gt;./configure --prefix=$HOME/FlightGear&amp;lt;/tt&amp;gt;. I would recommend installing all of OSG, plib, SimGear and FlightGear with the same prefix.&lt;br /&gt;
&lt;br /&gt;
=== Getting and compiling SimGear ===&lt;br /&gt;
&lt;br /&gt;
'''Step 1:'''&lt;br /&gt;
&lt;br /&gt;
Clone the SimGear git repository and set it up to track the 'next' branch.&lt;br /&gt;
 git clone git://gitorious.org/fg/simgear.git&lt;br /&gt;
&lt;br /&gt;
By default after cloning you should have a local next branch that tracks the master next branch. It can be updated it with git pull.&lt;br /&gt;
&lt;br /&gt;
'''Step 2:'''&lt;br /&gt;
&lt;br /&gt;
The source code will be downloaded into a directory called '''simgear'''.&lt;br /&gt;
&lt;br /&gt;
Next, go into the directory and make preparations for the compilation:&lt;br /&gt;
 cd simgear&lt;br /&gt;
 ''./autogen.sh''&lt;br /&gt;
 ./configure&lt;br /&gt;
&lt;br /&gt;
'''Note''' that if you don't want to install simgear globally on the system but in a specific directory, you can do so by adding --prefix=/path/to/your/fgInstallation to the ./configure command&lt;br /&gt;
&lt;br /&gt;
'''Step 3:'''&lt;br /&gt;
&lt;br /&gt;
Compile and install SimGear by doing:&lt;br /&gt;
 make; make install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Note:'' with gcc 4.2 or later,on some platforms, you can get compiling errors about alc.h like: &lt;br /&gt;
&lt;br /&gt;
 '&amp;lt;anonymous&amp;gt;' has incomplete type &lt;br /&gt;
take a look at http://bugs.gentoo.org/166723&lt;br /&gt;
&lt;br /&gt;
=== Getting and compiling FlightGear ===&lt;br /&gt;
&lt;br /&gt;
'''Step 1:'''&lt;br /&gt;
&lt;br /&gt;
Clone the FlightGear git repository and set it up to track the 'next' branch.&lt;br /&gt;
 git clone git://gitorious.org/fg/flightgear.git&lt;br /&gt;
&lt;br /&gt;
By default after cloning you should have a local next branch that tracks the master next branch. It can be updated it with git pull.&lt;br /&gt;
&lt;br /&gt;
'''Step 2:'''&lt;br /&gt;
&lt;br /&gt;
Next, go into the folder and make preparations for the compilation:&lt;br /&gt;
 cd flightgear&lt;br /&gt;
 ''./autogen.sh''&lt;br /&gt;
 ./configure&lt;br /&gt;
&lt;br /&gt;
Note that if you don't want to install simgear globally on the system but in a specific directory, you can do so by adding --prefix=/path/to/your/fgInstallation to the ./configure command.&lt;br /&gt;
If you didn't install OSG globally or in the same prefix as SimGear and FlightGear, you have to pass the OSG directory to the configure-command like this:&lt;br /&gt;
 ./configure --prefix=/path/to/fgInstallation --with-osg=/path/to/osg/installation --enable-osgviewer&lt;br /&gt;
In this case you have to tell your system where to find the OSG libraries before you can run flightgear:&lt;br /&gt;
  export LD_LIBRARY_PATH=/path/to/osgInstallation/lib:$LD_LIBRARY_PATH&lt;br /&gt;
&lt;br /&gt;
'''Step 3:'''&lt;br /&gt;
&lt;br /&gt;
Now you can compile and install Flightgear by:&lt;br /&gt;
 make; make install&lt;br /&gt;
&lt;br /&gt;
'''Step 4:'''&lt;br /&gt;
&lt;br /&gt;
Clone the data directory:&lt;br /&gt;
 git clone git://gitorious.org/fg/fgdata.git&lt;br /&gt;
&lt;br /&gt;
The data directory is large (almost 2.5GB) so it will take considerable time to download.&lt;br /&gt;
There mirror of fgdata that might be faster to download from:&lt;br /&gt;
 git clone git://mapserver.flightgear.org/fgdata&lt;br /&gt;
&lt;br /&gt;
The mirror is synchronized with the master so either will do.&lt;br /&gt;
&lt;br /&gt;
And install it in (or as) /usr/local/share/FlightGear&lt;br /&gt;
 mv fgdata /usr/local/share/flightgear&lt;br /&gt;
&lt;br /&gt;
== Distro-specific instructions ==&lt;br /&gt;
=== Debian/Ubuntu ===&lt;br /&gt;
* You can use the [[Scripted Compilation on Linux Debian/Ubuntu]] script to have Flightgear compiled in one shot under both Ubuntu and Debian systems.&lt;br /&gt;
* Debian users who prefer to build it without script may look at [[Building Flightgear - Debian]].&lt;br /&gt;
=== Gentoo ===&lt;br /&gt;
* Gentoo users can also use overlays to build FlightGear without much hassle: [[Building Flightgear - Gentoo]].&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
=== Instructions ===&lt;br /&gt;
*  [[MSYS]] &lt;br /&gt;
*  [[MinGW/cross-compiler]] &lt;br /&gt;
*  [[CodeBlocks IDE]] &lt;br /&gt;
*  [[OpenSUSE 10.1 10.2]] &lt;br /&gt;
* [http://www.geoffmclane.com/fg/fgmsvc7.htm MSVC7 *.Net]&lt;br /&gt;
* [http://www.oflebbe.de/oflebbe/FlightGear/index.html MSVC8 aka Visual 2005]&lt;br /&gt;
* [http://macflightgear.sourceforge.net/home/documents/ Mac OS X]&lt;br /&gt;
== Important note for GIT users ==&lt;br /&gt;
As of latest development in GIT, only cmake is now required for building both SimGear and FlightGear. So if you build GIT (for what any reason) please don't try to use autogen.sh as it is removed from repository.&lt;br /&gt;
&lt;br /&gt;
For detailed instructions, see page [[Building_using_CMake|Building using cmake]].&lt;br /&gt;
&lt;br /&gt;
{{Building}}&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Building_FlightGear_-_Linux&amp;diff=37795</id>
		<title>Building FlightGear - Linux</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Building_FlightGear_-_Linux&amp;diff=37795"/>
		<updated>2011-12-11T02:40:38Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* APT-GET List */ remove long line&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Main article|Building Flightgear}} &lt;br /&gt;
&lt;br /&gt;
This section describes how to build [[FlightGear]] on Linux system.&lt;br /&gt;
&lt;br /&gt;
Compiling FlightGear is not a task for novice users. Thus, if you're a beginner (we all were once) on a platform which binaries are available for, we recommend postponing this task and just starting with the binary distribution to get you flying.&lt;br /&gt;
&lt;br /&gt;
Or if you develop on Ubuntu or Debian, consider trying the script described in [[Scripted Compilation on Linux Debian/Ubuntu]].&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
Before you can compile FlightGear, you need to have the following installed on your computer:&lt;br /&gt;
&lt;br /&gt;
'''C++ compiler'''&lt;br /&gt;
&lt;br /&gt;
These are: c++, cpp, gcc, g++ found under the /usr/bin directory.  You will also need to have the tools '''autoconf''' and '''automake1.9''' installed.&lt;br /&gt;
&lt;br /&gt;
'''GIT'''&lt;br /&gt;
&lt;br /&gt;
See [[FlightGear and Git]].&lt;br /&gt;
&lt;br /&gt;
'''[[OpenGL]] support'''&lt;br /&gt;
&lt;br /&gt;
More specifically, your system needs the support for hardware accelerated graphics.  You can check for this by running the following in a [[command line]]:&lt;br /&gt;
&lt;br /&gt;
 glxinfo | grep direct&lt;br /&gt;
&lt;br /&gt;
Note: To run the above command, you need to have the tool '''mesa-utils''' installed.&lt;br /&gt;
&lt;br /&gt;
You should then see:&lt;br /&gt;
&lt;br /&gt;
 direct rendering: Yes&lt;br /&gt;
&lt;br /&gt;
This means you are good to go as far as OpenGL support is concerned.&lt;br /&gt;
&lt;br /&gt;
If you see:&lt;br /&gt;
&lt;br /&gt;
 direct rendering: No&lt;br /&gt;
&lt;br /&gt;
Don't panic yet.  This may just mean some required libraries for hardware accelerated graphic are missing.  Go ahead and try installing plib 1.8.5 and its dependencies first.  If you still get the above message, then you will need to do some googling and troubleshoot yourself.&lt;br /&gt;
&lt;br /&gt;
== Dependencies ==&lt;br /&gt;
FlightGear is dependent on quite a few number of libraries.  You do not need to compile all of them yourself, but you will at least need to have their development version installed.  For example, the development version for package plib1.8.5 is plib1.8.5'''-dev'''.&lt;br /&gt;
&lt;br /&gt;
The dependency is summarized in the following tree.  Please note that each library has its own dependencies, and most of these are not shown here.&lt;br /&gt;
&lt;br /&gt;
* FlightGear&lt;br /&gt;
** [http://kcat.strangesoft.net/openal.html OpenAL]&lt;br /&gt;
** SimGear&lt;br /&gt;
*** [http://plib.sourceforge.net/ PLIB]. Since March 2008, you will need version 1.8.5 - your distro probably supplies 1.8.4 still.&lt;br /&gt;
**** For versions pre March 2008: (Free)GLUT or SDL (We recommend the use of SDL over Free/GLUT, [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg16153.html however since March 2008, FreeGLUT as well as SDL are both considered depreciated, please only use --enable-osgviewer during configuration instead]) &lt;br /&gt;
***  [[OpenSceneGraph]]  (check link for compatible versions)&lt;br /&gt;
*** You also need the development files for several basic libraries to build the software, among them the following (the package names are for Debian and derivatives(?)):&lt;br /&gt;
**** libfreetype6-dev&lt;br /&gt;
**** libjpeg62-dev&lt;br /&gt;
**** libungif4-dev&lt;br /&gt;
**** libtiff4-dev&lt;br /&gt;
**** libpng12-dev&lt;br /&gt;
**** libxmu-dev&lt;br /&gt;
**** libxi-dev&lt;br /&gt;
**** zlib1g-dev&lt;br /&gt;
**** libglut3-dev&lt;br /&gt;
&lt;br /&gt;
If you attack the above dependencies in the order listed below, you should be good:&lt;br /&gt;
&lt;br /&gt;
1. Glut. Most distributions include glut packages, although you may have to hunt for them. Make sure you install both the glut and glut-devel packages, otherwise FlightGear may be able to compile but won't run correctly.&lt;br /&gt;
&lt;br /&gt;
2. Zlib. Most distributions install the basic zlib libraries by default, but not the development portions. If you don't have zlib.h, you probably need to install the zlib-devel package for your distribution. &lt;br /&gt;
&lt;br /&gt;
3. Plib - portability libraries and scene graph. &lt;br /&gt;
&lt;br /&gt;
4.  [[OpenSceneGraph]] &lt;br /&gt;
&lt;br /&gt;
5. SimGear - Simulation support libraries. If you are building FlightGear from Git, you need the Git version of SimGear. If you have strange build errors, one of the first things to check is that you have an up-to-date version of SimGear built and installed.&lt;br /&gt;
&lt;br /&gt;
==== APT-GET List ====&lt;br /&gt;
This is a list of all the apt-get commands I had to do while compiling FG, SG, and OSG on a mostly clean Ubuntu 64 system. It is a list of all the libraries you and your computer needs to compile FG, SG, OSG, and PLib. All you have to do is copy the full command, paste it in Terminal, enter your password, and it will download all the packages for you, and install them too. The full command is at the bottom, and I hope someone finds it useful :) sub-dependencies (dependencies of the dependencies) are not included as they are installed automatically by apt-get. If anyone sees something missing, please add it.&lt;br /&gt;
 &lt;br /&gt;
git - to get SG and FG&amp;lt;br /&amp;gt;&lt;br /&gt;
subversion - to get OSG&amp;lt;br /&amp;gt;&lt;br /&gt;
build-essential - to build (includes GCC, and other build tools)&amp;lt;br /&amp;gt;&lt;br /&gt;
cmake - OSG Uses this&amp;lt;br /&amp;gt;&lt;br /&gt;
cmake-curses-gui -- OSG Uses this&amp;lt;br /&amp;gt;&lt;br /&gt;
libpng-dev - to enable FG to use PNG textures&amp;lt;br /&amp;gt;&lt;br /&gt;
libfreetype6-dev - fonts&amp;lt;br /&amp;gt;&lt;br /&gt;
libjpeg-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libungif4-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libtiff-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libxmu-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libxi-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libglut3-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libalut-dev - sound&amp;lt;br /&amp;gt;&lt;br /&gt;
libboost-dev - makes coding for some developers easier&amp;lt;br /&amp;gt;&lt;br /&gt;
''automake - needed by ./autogen.sh files''&amp;lt;br /&amp;gt;&lt;br /&gt;
''autoconf - needed by ./autogen.sh files''&amp;lt;br /&amp;gt;&lt;br /&gt;
libfltk1.1-dev - You will need this if you will be using FGRun&amp;lt;br /&amp;gt;&lt;br /&gt;
-----------&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install git subversion build-essential cmake cmake-curses-gui libpng-dev libfreetype6-dev&lt;br /&gt;
libjpeg-dev libungif4-dev libtiff-dev libxmu-dev libxi-dev libglut3-dev libalut-dev&lt;br /&gt;
libboost-dev automake autoconf libfltk1.1-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
-----------&lt;br /&gt;
Total size is about 230 MB, depending on what you already have from other applications.&lt;br /&gt;
&lt;br /&gt;
This list might seem a bit short, but the sub-dependencies all add up :) The dependencies will be listed by apt-get when you use the command.&lt;br /&gt;
-----------&lt;br /&gt;
NOTE: On a Linux Mint 9 (Ubuntu 10.04) system this is the command I used:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install git-core subversion build-essential cmake cmake-curses-gui libpng-dev libfreetype6-dev libjpeg-dev libungif4-dev&lt;br /&gt;
libtiff-dev libxmu-dev libxi-dev libglut3-dev libalut-dev libboost-dev ''automake autoconf'' libfltk1.1-dev libplib-dev libopenscenegraph-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
libopenscenegraph-dev&lt;br /&gt;
You just need to copy that long line into a terminal and you should have all the packages you need to compile Flighgear and Simgear.&lt;br /&gt;
&lt;br /&gt;
== Compiling ==&lt;br /&gt;
Assuming you are root, do:&lt;br /&gt;
 cd /usr/local/src&lt;br /&gt;
&lt;br /&gt;
'''Note:''' When tracking a fast changing software like FlightGear/Git it is highly advisable to install it in a separate directory. That way one can also easily build and reinstall without being root, which greatly reduces the risk of messing up one's system.&lt;br /&gt;
To install in a directory of your choice add the &amp;lt;tt&amp;gt;--prefix&amp;lt;/tt&amp;gt; argument to configure. E.g. &amp;lt;tt&amp;gt;./configure --prefix=$HOME/FlightGear&amp;lt;/tt&amp;gt;. I would recommend installing all of OSG, plib, SimGear and FlightGear with the same prefix.&lt;br /&gt;
&lt;br /&gt;
=== Getting and compiling SimGear ===&lt;br /&gt;
&lt;br /&gt;
'''Step 1:'''&lt;br /&gt;
&lt;br /&gt;
Clone the SimGear git repository and set it up to track the 'next' branch.&lt;br /&gt;
 git clone git://gitorious.org/fg/simgear.git&lt;br /&gt;
&lt;br /&gt;
By default after cloning you should have a local next branch that tracks the master next branch. It can be updated it with git pull.&lt;br /&gt;
&lt;br /&gt;
'''Step 2:'''&lt;br /&gt;
&lt;br /&gt;
The source code will be downloaded into a directory called '''simgear'''.&lt;br /&gt;
&lt;br /&gt;
Next, go into the directory and make preparations for the compilation:&lt;br /&gt;
 cd simgear&lt;br /&gt;
 ''./autogen.sh''&lt;br /&gt;
 ./configure&lt;br /&gt;
&lt;br /&gt;
'''Note''' that if you don't want to install simgear globally on the system but in a specific directory, you can do so by adding --prefix=/path/to/your/fgInstallation to the ./configure command&lt;br /&gt;
&lt;br /&gt;
'''Step 3:'''&lt;br /&gt;
&lt;br /&gt;
Compile and install SimGear by doing:&lt;br /&gt;
 make; make install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Note:'' with gcc 4.2 or later,on some platforms, you can get compiling errors about alc.h like: &lt;br /&gt;
&lt;br /&gt;
 '&amp;lt;anonymous&amp;gt;' has incomplete type &lt;br /&gt;
take a look at http://bugs.gentoo.org/166723&lt;br /&gt;
&lt;br /&gt;
=== Getting and compiling FlightGear ===&lt;br /&gt;
&lt;br /&gt;
'''Step 1:'''&lt;br /&gt;
&lt;br /&gt;
Clone the FlightGear git repository and set it up to track the 'next' branch.&lt;br /&gt;
 git clone git://gitorious.org/fg/flightgear.git&lt;br /&gt;
&lt;br /&gt;
By default after cloning you should have a local next branch that tracks the master next branch. It can be updated it with git pull.&lt;br /&gt;
&lt;br /&gt;
'''Step 2:'''&lt;br /&gt;
&lt;br /&gt;
Next, go into the folder and make preparations for the compilation:&lt;br /&gt;
 cd flightgear&lt;br /&gt;
 ''./autogen.sh''&lt;br /&gt;
 ./configure&lt;br /&gt;
&lt;br /&gt;
Note that if you don't want to install simgear globally on the system but in a specific directory, you can do so by adding --prefix=/path/to/your/fgInstallation to the ./configure command.&lt;br /&gt;
If you didn't install OSG globally or in the same prefix as SimGear and FlightGear, you have to pass the OSG directory to the configure-command like this:&lt;br /&gt;
 ./configure --prefix=/path/to/fgInstallation --with-osg=/path/to/osg/installation --enable-osgviewer&lt;br /&gt;
In this case you have to tell your system where to find the OSG libraries before you can run flightgear:&lt;br /&gt;
  export LD_LIBRARY_PATH=/path/to/osgInstallation/lib:$LD_LIBRARY_PATH&lt;br /&gt;
&lt;br /&gt;
'''Step 3:'''&lt;br /&gt;
&lt;br /&gt;
Now you can compile and install Flightgear by:&lt;br /&gt;
 make; make install&lt;br /&gt;
&lt;br /&gt;
'''Step 4:'''&lt;br /&gt;
&lt;br /&gt;
Clone the data directory:&lt;br /&gt;
 git clone git://gitorious.org/fg/fgdata.git&lt;br /&gt;
&lt;br /&gt;
The data directory is large (almost 2.5GB) so it will take considerable time to download.&lt;br /&gt;
There mirror of fgdata that might be faster to download from:&lt;br /&gt;
 git clone git://mapserver.flightgear.org/fgdata&lt;br /&gt;
&lt;br /&gt;
The mirror is synchronized with the master so either will do.&lt;br /&gt;
&lt;br /&gt;
And install it in (or as) /usr/local/share/FlightGear&lt;br /&gt;
 mv fgdata /usr/local/share/flightgear&lt;br /&gt;
&lt;br /&gt;
== Distro-specific instructions ==&lt;br /&gt;
=== Debian/Ubuntu ===&lt;br /&gt;
* You can use the [[Scripted Compilation on Linux Debian/Ubuntu]] script to have Flightgear compiled in one shot under both Ubuntu and Debian systems.&lt;br /&gt;
* Debian users who prefer to build it without script may look at [[Building Flightgear - Debian]].&lt;br /&gt;
=== Gentoo ===&lt;br /&gt;
* Gentoo users can also use overlays to build FlightGear without much hassle: [[Building Flightgear - Gentoo]].&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
=== Instructions ===&lt;br /&gt;
*  [[MSYS]] &lt;br /&gt;
*  [[MinGW/cross-compiler]] &lt;br /&gt;
*  [[CodeBlocks IDE]] &lt;br /&gt;
*  [[OpenSUSE 10.1 10.2]] &lt;br /&gt;
* [http://www.geoffmclane.com/fg/fgmsvc7.htm MSVC7 *.Net]&lt;br /&gt;
* [http://www.oflebbe.de/oflebbe/FlightGear/index.html MSVC8 aka Visual 2005]&lt;br /&gt;
* [http://macflightgear.sourceforge.net/home/documents/ Mac OS X]&lt;br /&gt;
== Important note for GIT users ==&lt;br /&gt;
As of latest development in GIT, only cmake is now required for building both SimGear and FlightGear. So if you build GIT (for what any reason) please don't try to use autogen.sh as it is removed from repository.&lt;br /&gt;
&lt;br /&gt;
For detailed instructions, see page [[Building_using_CMake|Building using cmake]].&lt;br /&gt;
&lt;br /&gt;
{{Building}}&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Building_FlightGear_-_Linux&amp;diff=37716</id>
		<title>Building FlightGear - Linux</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Building_FlightGear_-_Linux&amp;diff=37716"/>
		<updated>2011-12-09T12:09:25Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Dependencies */ grammar&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Main article|Building Flightgear}} &lt;br /&gt;
&lt;br /&gt;
This section describes how to build [[FlightGear]] on Linux system.&lt;br /&gt;
&lt;br /&gt;
Compiling FlightGear is not a task for novice users. Thus, if you're a beginner (we all were once) on a platform which binaries are available for, we recommend postponing this task and just starting with the binary distribution to get you flying.&lt;br /&gt;
&lt;br /&gt;
Or if you develop on Ubuntu or Debian, consider trying the script described in [[Scripted Compilation on Linux Debian/Ubuntu]].&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
Before you can compile FlightGear, you need to have the following installed on your computer:&lt;br /&gt;
&lt;br /&gt;
'''C++ compiler'''&lt;br /&gt;
&lt;br /&gt;
These are: c++, cpp, gcc, g++ found under the /usr/bin directory.  You will also need to have the tools '''autoconf''' and '''automake1.9''' installed.&lt;br /&gt;
&lt;br /&gt;
'''GIT'''&lt;br /&gt;
&lt;br /&gt;
See [[FlightGear and Git]].&lt;br /&gt;
&lt;br /&gt;
'''[[OpenGL]] support'''&lt;br /&gt;
&lt;br /&gt;
More specifically, your system needs the support for hardware accelerated graphics.  You can check for this by running the following in a [[command line]]:&lt;br /&gt;
&lt;br /&gt;
 glxinfo | grep direct&lt;br /&gt;
&lt;br /&gt;
Note: To run the above command, you need to have the tool '''mesa-utils''' installed.&lt;br /&gt;
&lt;br /&gt;
You should then see:&lt;br /&gt;
&lt;br /&gt;
 direct rendering: Yes&lt;br /&gt;
&lt;br /&gt;
This means you are good to go as far as OpenGL support is concerned.&lt;br /&gt;
&lt;br /&gt;
If you see:&lt;br /&gt;
&lt;br /&gt;
 direct rendering: No&lt;br /&gt;
&lt;br /&gt;
Don't panic yet.  This may just mean some required libraries for hardware accelerated graphic are missing.  Go ahead and try installing plib 1.8.5 and its dependencies first.  If you still get the above message, then you will need to do some googling and troubleshoot yourself.&lt;br /&gt;
&lt;br /&gt;
== Dependencies ==&lt;br /&gt;
FlightGear is dependent on quite a few number of libraries.  You do not need to compile all of them yourself, but you will at least need to have their development version installed.  For example, the development version for package plib1.8.5 is plib1.8.5'''-dev'''.&lt;br /&gt;
&lt;br /&gt;
The dependency is summarized in the following tree.  Please note that each library has its own dependencies, and most of these are not shown here.&lt;br /&gt;
&lt;br /&gt;
* FlightGear&lt;br /&gt;
** [http://kcat.strangesoft.net/openal.html OpenAL]&lt;br /&gt;
** SimGear&lt;br /&gt;
*** [http://plib.sourceforge.net/ PLIB]. Since March 2008, you will need version 1.8.5 - your distro probably supplies 1.8.4 still.&lt;br /&gt;
**** For versions pre March 2008: (Free)GLUT or SDL (We recommend the use of SDL over Free/GLUT, [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg16153.html however since March 2008, FreeGLUT as well as SDL are both considered depreciated, please only use --enable-osgviewer during configuration instead]) &lt;br /&gt;
***  [[OpenSceneGraph]]  (check link for compatible versions)&lt;br /&gt;
*** You also need the development files for several basic libraries to build the software, among them the following (the package names are for Debian and derivatives(?)):&lt;br /&gt;
**** libfreetype6-dev&lt;br /&gt;
**** libjpeg62-dev&lt;br /&gt;
**** libungif4-dev&lt;br /&gt;
**** libtiff4-dev&lt;br /&gt;
**** libpng12-dev&lt;br /&gt;
**** libxmu-dev&lt;br /&gt;
**** libxi-dev&lt;br /&gt;
**** zlib1g-dev&lt;br /&gt;
**** libglut3-dev&lt;br /&gt;
&lt;br /&gt;
If you attack the above dependencies in the order listed below, you should be good:&lt;br /&gt;
&lt;br /&gt;
1. Glut. Most distributions include glut packages, although you may have to hunt for them. Make sure you install both the glut and glut-devel packages, otherwise FlightGear may be able to compile but won't run correctly.&lt;br /&gt;
&lt;br /&gt;
2. Zlib. Most distributions install the basic zlib libraries by default, but not the development portions. If you don't have zlib.h, you probably need to install the zlib-devel package for your distribution. &lt;br /&gt;
&lt;br /&gt;
3. Plib - portability libraries and scene graph. &lt;br /&gt;
&lt;br /&gt;
4.  [[OpenSceneGraph]] &lt;br /&gt;
&lt;br /&gt;
5. SimGear - Simulation support libraries. If you are building FlightGear from Git, you need the Git version of SimGear. If you have strange build errors, one of the first things to check is that you have an up-to-date version of SimGear built and installed.&lt;br /&gt;
&lt;br /&gt;
==== APT-GET List ====&lt;br /&gt;
This is a list of all the apt-get commands I had to do while compiling FG, SG, and OSG on a mostly clean Ubuntu 64 system. It is a list of all the libraries you and your computer needs to compile FG, SG, OSG, and PLib. All you have to do is copy the full command, paste it in Terminal, enter your password, and it will download all the packages for you, and install them too. The full command is at the bottom, and I hope someone finds it useful :) sub-dependencies (dependencies of the dependencies) are not included as they are installed automatically by apt-get. If anyone sees something missing, please add it.&lt;br /&gt;
 &lt;br /&gt;
git - to get SG and FG&amp;lt;br /&amp;gt;&lt;br /&gt;
subversion - to get OSG&amp;lt;br /&amp;gt;&lt;br /&gt;
build-essential - to build (includes GCC, and other build tools)&amp;lt;br /&amp;gt;&lt;br /&gt;
cmake - OSG Uses this&amp;lt;br /&amp;gt;&lt;br /&gt;
cmake-curses-gui -- OSG Uses this&amp;lt;br /&amp;gt;&lt;br /&gt;
libpng-dev - to enable FG to use PNG textures&amp;lt;br /&amp;gt;&lt;br /&gt;
libfreetype6-dev - fonts&amp;lt;br /&amp;gt;&lt;br /&gt;
libjpeg-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libungif4-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libtiff-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libxmu-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libxi-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libglut3-dev&amp;lt;br /&amp;gt;&lt;br /&gt;
libalut-dev - sound&amp;lt;br /&amp;gt;&lt;br /&gt;
libboost-dev - makes coding for some developers easier&amp;lt;br /&amp;gt;&lt;br /&gt;
''automake - needed by ./autogen.sh files''&amp;lt;br /&amp;gt;&lt;br /&gt;
''autoconf - needed by ./autogen.sh files''&amp;lt;br /&amp;gt;&lt;br /&gt;
libfltk1.1-dev - You will need this if you will be using FGRun&amp;lt;br /&amp;gt;&lt;br /&gt;
-----------&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install git subversion build-essential cmake cmake-curses-gui libpng-dev libfreetype6-dev&lt;br /&gt;
libjpeg-dev libungif4-dev libtiff-dev libxmu-dev libxi-dev libglut3-dev libalut-dev&lt;br /&gt;
libboost-dev automake autoconf libfltk1.1-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
-----------&lt;br /&gt;
Total size is about 230 MB, depending on what you already have from other applications.&lt;br /&gt;
&lt;br /&gt;
This list might seem a bit short, but the sub-dependencies all add up :) The dependencies will be listed by apt-get when you use the command.&lt;br /&gt;
-----------&lt;br /&gt;
NOTE: On a Linux Mint 9 (Ubuntu 10.04) system this is the command I used:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install git-core subversion build-essential cmake cmake-curses-gui libpng-dev libfreetype6-dev libjpeg-dev libungif4-dev libtiff-dev libxmu-dev libxi-dev libglut3-dev libalut-dev libboost-dev ''automake autoconf'' libfltk1.1-dev libplib-dev libopenscenegraph-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
libopenscenegraph-dev&lt;br /&gt;
You just need to copy that long line into a terminal and you should have all the packages you need to compile Flighgear and Simgear.&lt;br /&gt;
&lt;br /&gt;
== Compiling ==&lt;br /&gt;
Assuming you are root, do:&lt;br /&gt;
 cd /usr/local/src&lt;br /&gt;
&lt;br /&gt;
'''Note:''' When tracking a fast changing software like FlightGear/Git it is highly advisable to install it in a separate directory. That way one can also easily build and reinstall without being root, which greatly reduces the risk of messing up one's system.&lt;br /&gt;
To install in a directory of your choice add the &amp;lt;tt&amp;gt;--prefix&amp;lt;/tt&amp;gt; argument to configure. E.g. &amp;lt;tt&amp;gt;./configure --prefix=$HOME/FlightGear&amp;lt;/tt&amp;gt;. I would recommend installing all of OSG, plib, SimGear and FlightGear with the same prefix.&lt;br /&gt;
&lt;br /&gt;
=== Getting and compiling SimGear ===&lt;br /&gt;
&lt;br /&gt;
'''Step 1:'''&lt;br /&gt;
&lt;br /&gt;
Clone the SimGear git repository and set it up to track the 'next' branch.&lt;br /&gt;
 git clone git://gitorious.org/fg/simgear.git&lt;br /&gt;
&lt;br /&gt;
By default after cloning you should have a local next branch that tracks the master next branch. It can be updated it with git pull.&lt;br /&gt;
&lt;br /&gt;
'''Step 2:'''&lt;br /&gt;
&lt;br /&gt;
The source code will be downloaded into a directory called '''simgear'''.&lt;br /&gt;
&lt;br /&gt;
Next, go into the directory and make preparations for the compilation:&lt;br /&gt;
 cd simgear&lt;br /&gt;
 ''./autogen.sh''&lt;br /&gt;
 ./configure&lt;br /&gt;
&lt;br /&gt;
'''Note''' that if you don't want to install simgear globally on the system but in a specific directory, you can do so by adding --prefix=/path/to/your/fgInstallation to the ./configure command&lt;br /&gt;
&lt;br /&gt;
'''Step 3:'''&lt;br /&gt;
&lt;br /&gt;
Compile and install SimGear by doing:&lt;br /&gt;
 make; make install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Note:'' with gcc 4.2 or later,on some platforms, you can get compiling errors about alc.h like: &lt;br /&gt;
&lt;br /&gt;
 '&amp;lt;anonymous&amp;gt;' has incomplete type &lt;br /&gt;
take a look at http://bugs.gentoo.org/166723&lt;br /&gt;
&lt;br /&gt;
=== Getting and compiling FlightGear ===&lt;br /&gt;
&lt;br /&gt;
'''Step 1:'''&lt;br /&gt;
&lt;br /&gt;
Clone the FlightGear git repository and set it up to track the 'next' branch.&lt;br /&gt;
 git clone git://gitorious.org/fg/flightgear.git&lt;br /&gt;
&lt;br /&gt;
By default after cloning you should have a local next branch that tracks the master next branch. It can be updated it with git pull.&lt;br /&gt;
&lt;br /&gt;
'''Step 2:'''&lt;br /&gt;
&lt;br /&gt;
Next, go into the folder and make preparations for the compilation:&lt;br /&gt;
 cd flightgear&lt;br /&gt;
 ''./autogen.sh''&lt;br /&gt;
 ./configure&lt;br /&gt;
&lt;br /&gt;
Note that if you don't want to install simgear globally on the system but in a specific directory, you can do so by adding --prefix=/path/to/your/fgInstallation to the ./configure command.&lt;br /&gt;
If you didn't install OSG globally or in the same prefix as SimGear and FlightGear, you have to pass the OSG directory to the configure-command like this:&lt;br /&gt;
 ./configure --prefix=/path/to/fgInstallation --with-osg=/path/to/osg/installation --enable-osgviewer&lt;br /&gt;
In this case you have to tell your system where to find the OSG libraries before you can run flightgear:&lt;br /&gt;
  export LD_LIBRARY_PATH=/path/to/osgInstallation/lib:$LD_LIBRARY_PATH&lt;br /&gt;
&lt;br /&gt;
'''Step 3:'''&lt;br /&gt;
&lt;br /&gt;
Now you can compile and install Flightgear by:&lt;br /&gt;
 make; make install&lt;br /&gt;
&lt;br /&gt;
'''Step 4:'''&lt;br /&gt;
&lt;br /&gt;
Clone the data directory:&lt;br /&gt;
 git clone git://gitorious.org/fg/fgdata.git&lt;br /&gt;
&lt;br /&gt;
The data directory is large (almost 2.5GB) so it will take considerable time to download.&lt;br /&gt;
There mirror of fgdata that might be faster to download from:&lt;br /&gt;
 git clone git://mapserver.flightgear.org/fgdata&lt;br /&gt;
&lt;br /&gt;
The mirror is synchronized with the master so either will do.&lt;br /&gt;
&lt;br /&gt;
And install it in (or as) /usr/local/share/FlightGear&lt;br /&gt;
 mv fgdata /usr/local/share/flightgear&lt;br /&gt;
&lt;br /&gt;
== Distro-specific instructions ==&lt;br /&gt;
=== Debian/Ubuntu ===&lt;br /&gt;
* You can use the [[Scripted Compilation on Linux Debian/Ubuntu]] script to have Flightgear compiled in one shot under both Ubuntu and Debian systems.&lt;br /&gt;
* Debian users who prefer to build it without script may look at [[Building Flightgear - Debian]].&lt;br /&gt;
=== Gentoo ===&lt;br /&gt;
* Gentoo users can also use overlays to build FlightGear without much hassle: [[Building Flightgear - Gentoo]].&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
=== Instructions ===&lt;br /&gt;
*  [[MSYS]] &lt;br /&gt;
*  [[MinGW/cross-compiler]] &lt;br /&gt;
*  [[CodeBlocks IDE]] &lt;br /&gt;
*  [[OpenSUSE 10.1 10.2]] &lt;br /&gt;
* [http://www.geoffmclane.com/fg/fgmsvc7.htm MSVC7 *.Net]&lt;br /&gt;
* [http://www.oflebbe.de/oflebbe/FlightGear/index.html MSVC8 aka Visual 2005]&lt;br /&gt;
* [http://macflightgear.sourceforge.net/home/documents/ Mac OS X]&lt;br /&gt;
== Important note for GIT users ==&lt;br /&gt;
As of latest development in GIT, only cmake is now required for building both SimGear and FlightGear. So if you build GIT (for what any reason) please don't try to use autogen.sh as it is removed from repository.&lt;br /&gt;
&lt;br /&gt;
For detailed instructions, see page [[Building_using_CMake|Building using cmake]].&lt;br /&gt;
&lt;br /&gt;
{{Building}}&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Portal:User&amp;diff=37618</id>
		<title>Portal:User</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Portal:User&amp;diff=37618"/>
		<updated>2011-12-06T01:36:13Z</updated>

		<summary type="html">&lt;p&gt;Moksha: add piped link for framerates&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{PortalMenu}}&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;border-spacing:8px; margin:0px -8px;&amp;quot;&lt;br /&gt;
|class=&amp;quot;MainPageBG&amp;quot; style=&amp;quot;width:100%; border:1px solid #d9e2e2; background:#efefef; vertical-align:top; color:#000;&amp;quot;|&lt;br /&gt;
{|width=&amp;quot;100%&amp;quot; cellpadding=&amp;quot;1&amp;quot; cellspacing=&amp;quot;5&amp;quot; style=&amp;quot;vertical-align:top; background:#efefef;&amp;quot;&lt;br /&gt;
! &amp;lt;h2 style=&amp;quot;margin:0; background:#0f7a71; font-size:120%; font-weight:bold; border:1px solid #d9e2e2; text-align:left; color:white; padding:0.2em 0.4em;&amp;quot;&amp;gt;The User Portal&amp;lt;/h2&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;color:#000;&amp;quot;| &lt;br /&gt;
This portal is for the users of FlightGear. To be sure you get the latest news, it's a good idea to subscribe yourself to the [http://lists.sourceforge.net/lists/listinfo/flightgear-users FlightGear users] -mailing list. An [http://sourceforge.net/mailarchive/forum.php?forum_name=flightgear-users archive of the list] is available and should be checked before asking again. Also, there's a users forum to be found at http://www.flightgear.org/forums.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;border-spacing:8px; margin:0px -8px;&amp;quot;&lt;br /&gt;
|class=&amp;quot;MainPageBG&amp;quot; style=&amp;quot;width:33%; border:1px solid #d9e2e2; background:#efefef; vertical-align:top; color:#000;&amp;quot;|&lt;br /&gt;
{|width=&amp;quot;100%&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;5&amp;quot; style=&amp;quot;vertical-align:top; background:#efefef;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! &amp;lt;h2 style=&amp;quot;margin:0; background:#0f7a71; font-size:120%; font-weight:bold; border:1px solid #d9e2e2; text-align:left; color:white; padding:0.2em 0.4em;&amp;quot;&amp;gt;Getting Started&amp;lt;/h2&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;color:#000;&amp;quot;| &lt;br /&gt;
*  [[New to FlightGear]] &lt;br /&gt;
*  [[Unique Features]]&lt;br /&gt;
*  [[FlightGear Manual]] &lt;br /&gt;
*  [[Frequently asked questions]] &lt;br /&gt;
*  [[Video Tutorials]]&lt;br /&gt;
*  [[Hardware Recommendations]] &lt;br /&gt;
*  [[Notebooks known to run FlightGear]]&lt;br /&gt;
*  [[Recommended Software]] &lt;br /&gt;
*  [[Troubleshooting Problems]] &lt;br /&gt;
*  [[Volunteer]] &lt;br /&gt;
|-&lt;br /&gt;
! &amp;lt;h2 style=&amp;quot;margin:0; background:#0f7a71; font-size:120%; font-weight:bold; border:1px solid #d9e2e2; text-align:left; color:white; padding:0.2em 0.4em;&amp;quot;&amp;gt;Using Flightgear&amp;lt;/h2&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;color:#000;&amp;quot;| &lt;br /&gt;
*  [[Aircraft]] &lt;br /&gt;
*  [[Helicopter]] &lt;br /&gt;
*  [[Vehicle]] &lt;br /&gt;
*  [[Chat Menu]] &lt;br /&gt;
*  [[Doing aerotow over the net]] &lt;br /&gt;
*  [[Dual control]] &lt;br /&gt;
*  [[Flying the Helicopter]] &lt;br /&gt;
*  [[Instant Replay]] &lt;br /&gt;
*  [[Menubar]]&lt;br /&gt;
*  [[Preset Properties]] &lt;br /&gt;
*  [[Realism]] &lt;br /&gt;
*  [[Starting in the Air]] &lt;br /&gt;
*  [[Table of models]]&lt;br /&gt;
*  [[FlightGear related projects]]&lt;br /&gt;
* [http://www.nanjika.co.uk/flightgear/FGShortRef.pdf FlightGear Short Reference] &amp;lt;small&amp;gt;pdf, 80 kB&amp;lt;/small&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! &amp;lt;h2 style=&amp;quot;margin:0; background:#0f7a71; font-size:120%; font-weight:bold; border:1px solid #d9e2e2; text-align:left; color:white; padding:0.2em 0.4em;&amp;quot;&amp;gt;Configuring Flightgear&amp;lt;/h2&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;color:#000;&amp;quot;|&lt;br /&gt;
*  [[Multi core and Multi GPU support]]  &lt;br /&gt;
*  [[Command Line Parameters]] &lt;br /&gt;
*  [[Downloading New Flightgear Scenery for Windows XP]]&lt;br /&gt;
*  [[Installing Scenery]] &lt;br /&gt;
*  [[Installing Aircraft]] &lt;br /&gt;
*  [[Howto: Improve framerates | Improving Framerates]] &lt;br /&gt;
* [[Joystick]]&lt;br /&gt;
*  [[Linux software audio mixing with FlightGear]] &lt;br /&gt;
*  [[Multiplayer Howto]] &lt;br /&gt;
* [http://www.inkdrop.net/dave/multimon.pdf Using multiple monitors with FlightGear]&lt;br /&gt;
*  [[Howto:Configure Camera View Windows]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
|class=&amp;quot;MainPageBG&amp;quot; style=&amp;quot;width:33%; border:1px solid #d9e2e2; background:#efefef; vertical-align:top&amp;quot;|&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;5&amp;quot; style=&amp;quot;vertical-align:top; background:#efefef;&amp;quot;&lt;br /&gt;
! &amp;lt;h2 style=&amp;quot;margin:0; background:#0f7a71; font-size:120%; font-weight:bold; border:1px solid #d9e2e2; text-align:left; color:white; padding:0.2em 0.4em;&amp;quot;&amp;gt;FlightGear Community/Events&amp;lt;/h2&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;color:#000;&amp;quot;| &lt;br /&gt;
* [[FlightGear Airways]]&lt;br /&gt;
* [[FlightGear Race]]&lt;br /&gt;
* [[Pilots of the Caribbean]]&lt;br /&gt;
|-&lt;br /&gt;
! &amp;lt;h2 style=&amp;quot;margin:0; background:#0f7a71; font-size:120%; font-weight:bold; border:1px solid #d9e2e2; text-align:left; color:white; padding:0.2em 0.4em;&amp;quot;&amp;gt;Interactive Scenarios&amp;lt;/h2&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;color:#000;&amp;quot;|&lt;br /&gt;
*  [[AI Systems]]  &lt;br /&gt;
*  [[Interactive Traffic]] &lt;br /&gt;
*  [[Soaring]] &lt;br /&gt;
*  [[Bombable add-on (dogfighting and weapons)]]&lt;br /&gt;
|-&lt;br /&gt;
! &amp;lt;h2 style=&amp;quot;margin:0; background:#0f7a71; font-size:120%; font-weight:bold; border:1px solid #d9e2e2; text-align:left; color:white; padding:0.2em 0.4em;&amp;quot;&amp;gt;Howtos&amp;lt;/h2&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;color:#000;&amp;quot;|&lt;br /&gt;
* [[Howto: Multi-computing FlightGear|Multi-computing FlightGear]]&lt;br /&gt;
* [[Howto: Air-Air Refueling|Air-Air Refueling]]&lt;br /&gt;
* [[Howto: Be a controller|Be a controller]]&lt;br /&gt;
* [[Howto: Carrier|Carrier]]&lt;br /&gt;
* [[Howto: Get rid of common errors|Get rid of common errors]]&lt;br /&gt;
* [[Howto: Multiplayer|Multiplayer]]&lt;br /&gt;
* [[Howto: Make nice screenshots|Make nice screenshots]]&lt;br /&gt;
* [[Howto: 737-300|737-300]]&lt;br /&gt;
'''[[:Category:Howto|More...]]'''&lt;br /&gt;
|-&lt;br /&gt;
! &amp;lt;h2 style=&amp;quot;margin:0; background:#0f7a71; font-size:120%; font-weight:bold; border:1px solid #d9e2e2; text-align:left; color:white; padding:0.2em 0.4em;&amp;quot;&amp;gt;Tutorials&amp;lt;/h2&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;color:#000;&amp;quot;|&lt;br /&gt;
*  [[ATC Tutorial]] &lt;br /&gt;
*  [[Instrument Landing System Tutorial]] &lt;br /&gt;
*  [[Updating FlightGear on Windows]]&lt;br /&gt;
|-&lt;br /&gt;
! &amp;lt;h2 style=&amp;quot;margin:0; background:#0f7a71; font-size:120%; font-weight:bold; border:1px solid #d9e2e2; text-align:left; color:white; padding:0.2em 0.4em;&amp;quot;&amp;gt;Using additional FlightGear Tools&amp;lt;/h2&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;color:#000;&amp;quot;| &lt;br /&gt;
*  [[FGo!]]  - Simple GUI for launching FlightGear&lt;br /&gt;
*  [[Fgrun]]  - aka the FlightGear Wizard&lt;br /&gt;
*  [[KFreeFlight]]  - GUI like fgrun but with KDE dependencies&lt;br /&gt;
*  [[FGCOM]]  - realtime voice comms&lt;br /&gt;
*  [[Atlas]]  - How to set it up&lt;br /&gt;
* [[Airport Diagram Generator]] - create charts from FlightGears data&lt;br /&gt;
|-&lt;br /&gt;
! &amp;lt;h2 style=&amp;quot;margin:0; background:#0f7a71; font-size:120%; font-weight:bold; border:1px solid #d9e2e2; text-align:left; color:white; padding:0.2em 0.4em;&amp;quot;&amp;gt;FlightGear Promotion&amp;lt;/h2&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;color:#000;&amp;quot;|&lt;br /&gt;
* [[Unique Features]] &lt;br /&gt;
* [[FlightGear Reviews]]&lt;br /&gt;
* [[FlightGear Videos]]&lt;br /&gt;
* [[FlightGear 1.0 features showcase]] &lt;br /&gt;
* [[Logos|FlightGear Logos]]&lt;br /&gt;
* [[Presentation Recipe]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
|class=&amp;quot;MainPageBG&amp;quot; style=&amp;quot;width:33%; border:1px solid #d9e2e2; background:#efefef; vertical-align:top&amp;quot;|&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;5&amp;quot; style=&amp;quot;vertical-align:top; background:#efefef;&amp;quot;&lt;br /&gt;
! &amp;lt;h2 style=&amp;quot;margin:0; background:#0f7a71; font-size:120%; font-weight:bold; border:1px solid #d9e2e2; text-align:left; color:white; padding:0.2em 0.4em;&amp;quot;&amp;gt;Suggested&amp;lt;/h2&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;color:#000;&amp;quot;| &lt;br /&gt;
&lt;br /&gt;
*  [[Suggested Aircraft]] &lt;br /&gt;
*  [[Suggested Airports/Scenery]] &lt;br /&gt;
*  [[Suggested Flights]] &lt;br /&gt;
* [[Suggested Prerecorded Flights]] &amp;lt;small&amp;gt; New! &amp;lt;/small&amp;gt;&lt;br /&gt;
*  [[Challenging Airports]]&lt;br /&gt;
*  [[Suggested Software]] &lt;br /&gt;
|-&lt;br /&gt;
! &amp;lt;h2 style=&amp;quot;margin:0; background:#0f7a71; font-size:120%; font-weight:bold; border:1px solid #d9e2e2; text-align:left; color:white; padding:0.2em 0.4em;&amp;quot;&amp;gt;Top Rated Aircraft&amp;lt;/h2&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;color:#000;&amp;quot;|&lt;br /&gt;
&amp;lt;w4g_ratinglist numberofitems=&amp;quot;10&amp;quot; category=&amp;quot;Aircraft&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''[[Ratings|More...]]'''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
__NOEDITSECTION__&lt;br /&gt;
&lt;br /&gt;
[[de:Portal:Benutzer]]&lt;br /&gt;
[[es:Portal:Usuario]]&lt;br /&gt;
[[pl:Portal:Dla użytkowników]]&lt;br /&gt;
[[fr:Portal:Utilisateur]]&lt;br /&gt;
[[zh:Portal:用户]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Scripted_Compilation_on_Linux_Debian/Ubuntu&amp;diff=37617</id>
		<title>Scripted Compilation on Linux Debian/Ubuntu</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Scripted_Compilation_on_Linux_Debian/Ubuntu&amp;diff=37617"/>
		<updated>2011-12-06T01:07:19Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Disk usage */ sentence structure&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Description==&lt;br /&gt;
The following script takes care of downloading and compiling FlightGear from the git repositories with just one command execution for both 32-bit and 64-bit Debian based systems (Debian, Ubuntu). Pre-existing installed version (if any) of FlightGear are not touched at all since the script builds and installs everything under the directory in which it is launched.&lt;br /&gt;
&lt;br /&gt;
Necessary packages are installed via the apt-get system while libraries not included in the repositories are downloaded and compiled on the fly (i.e. [[Plib]], [[Simgear]] and [[OSG]]).&lt;br /&gt;
&lt;br /&gt;
=== List of compiled programs ===&lt;br /&gt;
The script is able to download and compile:&lt;br /&gt;
* FlightGear (And all the data needed to use it)&lt;br /&gt;
* [[Fgrun]]&lt;br /&gt;
* [[FGCOM]]&lt;br /&gt;
* [[FGComGui]]&lt;br /&gt;
* [[FGo!]]&lt;br /&gt;
* [[Atlas]]&lt;br /&gt;
* [[Terrasync]]&lt;br /&gt;
&lt;br /&gt;
== Download ==&lt;br /&gt;
You can download the script here: [http://www.gitorious.org/fg/fgmeta/blobs/raw/master/download_and_compile.sh download_and_compile.sh]&lt;br /&gt;
&lt;br /&gt;
The script is maintained in the FlightGear main repository. Remember to update this script whenever a new FlightGear version is released, so that you'll be able to download the latest stable revision.&lt;br /&gt;
&lt;br /&gt;
There is also another option for building FlightGear and all its dependencies in an automated fashion, please refer to: http://geoffmclane.com/fg/fgfs-052.htm&lt;br /&gt;
&lt;br /&gt;
== Instructions ==&lt;br /&gt;
To run download_and_compile.sh, just save it in a directory called for example: ~/fgfs&lt;br /&gt;
then execute it (no need to execute it as root).&lt;br /&gt;
&lt;br /&gt;
Here is for example a sequence of commands to get the script:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir ~/fgfs&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
wget http://www.gitorious.org/fg/fgmeta/blobs/raw/master/download_and_compile.sh&lt;br /&gt;
chmod 755 download_and_compile.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You have two options now: build the latest ''stable'' FlightGear release or build the ''current development'' version (bleeding edge).&lt;br /&gt;
&lt;br /&gt;
=== Build the latest stable FlightGear release ===&lt;br /&gt;
When executing the script, use the &amp;quot;-s&amp;quot; option to build the latest stable release:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sh download_and_compile.sh -s&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Build the current FlightGear development verison ===&lt;br /&gt;
When executing the script without any option, the latest development version is built.&lt;br /&gt;
&lt;br /&gt;
'''Warning''': The development version changes on an almost daily basis. It provides the latest features, but is not always guaranteed to work reliably. If you're unfamiliar with software testing, you may prefer to use the latest stable release.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sh download_and_compile.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once the script is finished, you will successfully get Flightgear and Fgrun installed in the ~/fgfs directory.&lt;br /&gt;
&lt;br /&gt;
=== Launching FlightGear ===&lt;br /&gt;
To run your new git installation of FlightGear you have to launch the ''run_fgfs.sh'' command under the same folder, for example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_fgfs.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Launching Fgrun ===&lt;br /&gt;
[[File:fgrun-page2.jpg|thumb|right]]&lt;br /&gt;
For many users it's more comfortable having FlightGear launched by the graphical utility Fgrun which is installed as well in the same folder. You have to launch the ''run_fgrun.sh'' command, for example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_fgrun.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Launching Fgo! ===&lt;br /&gt;
[[File:Fgo01.jpg|thumb|left]]&lt;br /&gt;
This is a graphical utility written in [[python]], You have to launch the ''run_fgo.sh'' command, for example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_fgo.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Remember that the first time you run it, you have to go to preferences and set the binary and fgdata path (Do no set the working directory, you don't need it).&lt;br /&gt;
&lt;br /&gt;
== Additional programs ==&lt;br /&gt;
If you wish to get all the other programs, you need to launch the script adding the &amp;quot;ALL&amp;quot; option to the command line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sh download_and_compile.sh ALL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This, will also install FGCOM, FGComGui and Atlas&lt;br /&gt;
&lt;br /&gt;
=== Launching FGCOM ===&lt;br /&gt;
FGCOM is the system used by FlightGear to simulate radio communications between users. Launch it using the ''run_fgcom.sh'' command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_fgcom.sh -cs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Launching FGComGui ===&lt;br /&gt;
FgComGui is a GUI wrapper to launch fgcom.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs  &lt;br /&gt;
sh run_fgcomgui.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Launching Atlas ===&lt;br /&gt;
[[File:Atlas.jpg|thumb]]&lt;br /&gt;
Atlas provides a map for FlightGear, use it launching: ''run_atlas.sh''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_atlas.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Launching Terrasync ===&lt;br /&gt;
Your FlightGear compilation comes with the Terrasync program too, so if you want to use it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_terrasync.sh -S -p 5500 -d /folder/with/sceneries&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Where: ''/folder/with/sceneries'' is the folder containing the sceneries data.&lt;br /&gt;
&lt;br /&gt;
Then launch fgfs with the '''--fg-scenery=/folder/with/sceneries --atlas=socket,out,5,localhost,5500,udp''' option&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Compilation errors ===&lt;br /&gt;
Here we are, no fear, if you wish to use programs from the cvs/svn/git repositories, you might face compilation errors that will prevent you to have a working copy of one or more of the programs provided by this script. What can be the causes that prevent us from successfully compiling? As far as I know those:&lt;br /&gt;
# Software developers introduce a new functionality with a new piece of code that prevents the compilation under your architecture, this can happen working with cvs/svn/git sources.&lt;br /&gt;
# The program refuses to compile because of a divergence in the libraries on which it depends. For example FlightGear might not compile because OSG has been modified, while OSG itself compiles fine, FG won't.&lt;br /&gt;
# One or more repositories are down and you can't get the library you need. (Both from cvs/svn/git or apt-get)&lt;br /&gt;
&lt;br /&gt;
There is a simple solution to the above errors: wait and relaunch the script after some time (hours or days), if software developers repair or synchronize their code with the newly updated libraries (which generally happens eventually), your FlightGear will compile fine as if the previous error never took place.&lt;br /&gt;
&lt;br /&gt;
Sometimes it happens that the script fails to compile only fgrun, fgcom or atlas, if you then see the run_fgfs.sh file it means that FlightGear installation was successful and you can safely run it.&lt;br /&gt;
&lt;br /&gt;
== Options ==&lt;br /&gt;
The script by default (without any option) will only compile FlightGear and Fgrun. To make it compile all, you need to launch the script with the ''ALL'' parameter. i.e.:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sh download_and_compile.sh ALL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compiling only one program ===&lt;br /&gt;
If you wish to recompile only one of the programs you can launch the script with one of the following parameters:&lt;br /&gt;
* PLIB (to compile and install only plib)&lt;br /&gt;
* OSG (to compile and install only OpenSceneGraph)&lt;br /&gt;
* SIMGEAR (to compile and install only Simgear)&lt;br /&gt;
* FGFS (to compile and install only FlightGear)&lt;br /&gt;
* DATA (to download / update only data files for FlightGear)&lt;br /&gt;
* FGRUN (to compile and install only Fgrun)&lt;br /&gt;
* FGO (to compile and install only Fgo!)&lt;br /&gt;
* FGCOM (to compile and install only Fgcom)&lt;br /&gt;
* FGCOMGUI (to compile and install only FgComGui)&lt;br /&gt;
* ATLAS (to compile and install only Atlas)&lt;br /&gt;
&lt;br /&gt;
=== Fast updating ===&lt;br /&gt;
There is a second parameter ''UPDATE'' that allows you to just update your installation. i.e.:&lt;br /&gt;
This will only update FGFS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sh download_and_compile.sh FGFS UPDATE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compiling last stable versions (Experimental) ===&lt;br /&gt;
Even if the script fetches data and sources from bleeding edge developers repositories (which sometimes do not compile), you can still force the script to download latest known versions of the software that were compiling successfully by adding the -s option.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sh download_and_compile.sh -s&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
How does it work? Inside the script there is a small list with latest known versions of successfully compiling revisions, it will download from svn/git those specific revisions, which have been found able to compile together.&amp;lt;BR/&amp;gt;&lt;br /&gt;
Warning: If you run this option inside a folder where you previously compiled fgfs, it will probably fail to compile, you better run the script with this option inside an empty folder or a folder whith the same fgfs version compiled previously.&lt;br /&gt;
&lt;br /&gt;
=== Advanced options ===&lt;br /&gt;
* Skip download of packages using '''-p n''' option&lt;br /&gt;
* Skip compilation of programs using '''-c n''' option&lt;br /&gt;
* Skip retrieving software updates using '''-d n''' option&lt;br /&gt;
* Skip reconfigure (make clean) using '''-r n''' option&lt;br /&gt;
&lt;br /&gt;
For example, if you are a developer and wish to quickly recompile and reinstall only your own modifications for FlightGear do this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sh download_and_compile.sh -p n -d n -r n  FGFS&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
this will only recompile modifications and reinstall them.&lt;br /&gt;
&lt;br /&gt;
=== Multicore Acceleration ===&lt;br /&gt;
Using the option '''-j x''' (where x is the number of your CPU-Cores you wish to assign to the job) will speed up the whole compilation process considerably.&lt;br /&gt;
&lt;br /&gt;
== Disk usage ==&lt;br /&gt;
Having both compiled program, source code, and data from git requires some hard disk space: It will take something like 11 GB of space.&lt;br /&gt;
If you don't have a fast machine, it will require several hours of compilation time.&lt;br /&gt;
&lt;br /&gt;
[[nl:Compileren met een Script op Linux Debian/Ubuntu]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Input_device&amp;diff=37615</id>
		<title>Input device</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Input_device&amp;diff=37615"/>
		<updated>2011-12-05T23:53:20Z</updated>

		<summary type="html">&lt;p&gt;Moksha: typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Could you imagine a pilot in his or her [[:Category:Cessna|Cessna]] controlling the machine with a keyboard alone? For getting the proper feeling of flight you will need a '''joystick/yoke''' plus [[rudder]] pedals, right? However, the combination of numerous types of joysticks, flightsticks, yokes, pedals and several target operating systems, makes joystick support a nontrivial task in [[FlightGear]]. &lt;br /&gt;
&lt;br /&gt;
FlightGear has integrated joystick support, which automatically detects any joystick, yoke, or pedals attached. Just try it! If this does work for you, lean back and be happy! You can see what FlightGear has detected your joystick as in the Help &amp;gt; Joystick Information dialog from the [[menu]]. &lt;br /&gt;
&lt;br /&gt;
Unfortunately, for the above mentioned versatility, chances are your joystick does not work out of the box. Basically, there are two alternative approaches to get it going, with the first one being preferred.&lt;br /&gt;
&lt;br /&gt;
== Built-in joystick support ==&lt;br /&gt;
&lt;br /&gt;
=== General remarks ===&lt;br /&gt;
In order for joystick auto-detection to work, a joystick bindings xml file must exist for each joystick. This file describes what axes and buttons are to be used to control which functions in FlightGear. The associations between functions and axes or buttons are called “bindings”. This bindings file can have any name as long as a corresponding entry exists in the joysticks description file &amp;lt;tt&amp;gt;[[$FG_ROOT]]/joysticks.xml&amp;lt;/tt&amp;gt;, which tells FlightGear where to look for all the bindings files. We will look at examples later. &lt;br /&gt;
&lt;br /&gt;
FlightGear includes several such bindings files for several joystick manufacturers in folders named for each manufacturer. For example, if you have a CH Products joystick, look in the folder &amp;lt;tt&amp;gt;[[$FG_ROOT]]/Input/Joysticks/CH&amp;lt;/tt&amp;gt; for a file that might work for your joystick. If such a file exists and your joystick is working with other applications, then it should work with FlightGear the first time you run it. The latest config files are always to be found at https://gitorious.org/fg/fgdata/trees/master/Input/Joysticks.&lt;br /&gt;
&lt;br /&gt;
If such a file does not exist, you will have to create such a file. We will discuss that in [[Joystick#Writing or editing joystick binding xml files|a later section]], by cutting and pasting bindings from the examples that are included with FlightGear.&lt;br /&gt;
&lt;br /&gt;
=== Verifying your joystick is working ===&lt;br /&gt;
==== Linux ====&lt;br /&gt;
Reboot your system and immediately enter on the [[command line]] &lt;br /&gt;
&lt;br /&gt;
 dmesg | grep Joystick &lt;br /&gt;
&lt;br /&gt;
which pipes the boot message to grep which then prints every line in the boot message that contains the string “Joystick”. When you do this with a Saitek joystick attached, you will see a line similar to this one: &lt;br /&gt;
&lt;br /&gt;
 input0: USB HID v1.00 Joystick [SAITEK CYBORG 3D USB] on usb2:3.0 &lt;br /&gt;
&lt;br /&gt;
This line tells us that a joystick has identified itself as SAITEK CYBORG 3D USB to the operating system. It does not tell us that the joystick driver sees your joystick. &lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
Go to &amp;lt;tt&amp;gt;Start &amp;gt; Control Panel &amp;gt; Game Controller&amp;lt;/tt&amp;gt; and see whether the dialog displays (and responses) on your joystick. &lt;br /&gt;
&lt;br /&gt;
=== Confirming that the driver recognizes your joystick ===&lt;br /&gt;
FlightGear ships with a utility called js_demo. It will report the number of joysticks attached to a system, their respective &amp;quot;names&amp;quot; and their capabilities. Under Linux, you can run js_demo from the folder /FlightGear/bin as follows: &lt;br /&gt;
&lt;br /&gt;
 $ cd /usr/local/FlightGear/bin &lt;br /&gt;
 $ js_demo &lt;br /&gt;
&lt;br /&gt;
Under Windows, open a command shell (&amp;lt;tt&amp;gt;Start &amp;gt; All Programs &amp;gt; Accessories &amp;gt; Command Prompt&amp;lt;/tt&amp;gt;), go to the FlightGear binary folder and start the program as follows (given FlightGear is installed under &amp;lt;tt&amp;gt;C:/Program Files/Flightgear&amp;lt;/tt&amp;gt;) &lt;br /&gt;
&lt;br /&gt;
 C:&lt;br /&gt;
 cd /Program Files/FlightGear/bin/win32 &lt;br /&gt;
 js_demo.exe &lt;br /&gt;
&lt;br /&gt;
If js_demo.exe is not included in your version, download it [http://fgfs.beggabaur.de/forum/js_demo.exe here].&lt;br /&gt;
&lt;br /&gt;
On our system, the first few lines of output are (stop the program with C if it is quickly scrolling past your window!) as follows: &lt;br /&gt;
&lt;br /&gt;
 Joystick test program. &lt;br /&gt;
 Joystick 0: “CH PRODUCTS CH FLIGHT SIM YOKE USB ” &lt;br /&gt;
 Joystick 1: “CH PRODUCTS CH PRO PEDALS USB” &lt;br /&gt;
 Joystick 2 not detected &lt;br /&gt;
 Joystick 3 not detected &lt;br /&gt;
 Joystick 4 not detected &lt;br /&gt;
 Joystick 5 not detected &lt;br /&gt;
 Joystick 6 not detected &lt;br /&gt;
 Joystick 7 not detected &lt;br /&gt;
 +——————–JS.0———————-+——————–JS.1———————-+ &lt;br /&gt;
 | Btns Ax:0 Ax:1 Ax:2 Ax:3 Ax:4 Ax:5 Ax:6 | Btns Ax:0 Ax:1 Ax:2 | &lt;br /&gt;
 +———————————————-+———————————————-+ &lt;br /&gt;
 | 0000 +0.0 +0.0 +1.0 -1.0 -1.0 +0.0 +0.0 . | 0000 -1.0 -1.0 -1.0 . . . . . | &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First note that js demo reports which number is assigned to each joystick recognized by the driver. Also, note that the “name” each joystick reports is also included between quotes. We will need the names for each bindings file when we begin writing the binding xml files for each joystick.&lt;br /&gt;
&lt;br /&gt;
=== Identifying the numbering of axes and buttons ===&lt;br /&gt;
Axis and button numbers can be identified using js demo as follows. By observing the output of js demo while working your joystick axes and buttons you can determine what axis and button numbers are assigned to each joystick axis and button. It should be noted that numbering generally starts with zero. &lt;br /&gt;
&lt;br /&gt;
The buttons are handled internally as a binary number in which bit 0 (the least significant bit) represents button 0, bit 1 represents button 1, etc., but this number is displayed on the screen in hexadecimal notation, so: &lt;br /&gt;
&lt;br /&gt;
* 0001 ⇒ button 0 pressed &lt;br /&gt;
* 0002 ⇒ button 1 pressed &lt;br /&gt;
* 0004 ⇒ button 2 pressed &lt;br /&gt;
* 0008 ⇒ button 3 pressed &lt;br /&gt;
* 0010 ⇒ button 4 pressed &lt;br /&gt;
* 0020 ⇒ button 5 pressed &lt;br /&gt;
* 0040 ⇒ button 6 pressed &lt;br /&gt;
* ... etcp to ... &lt;br /&gt;
* 8000 ⇒ button 15 pressed &lt;br /&gt;
* ... and ... &lt;br /&gt;
* 0014 ⇒ buttons 2 and 4 pressed simultaneously &lt;br /&gt;
* ... etc. &lt;br /&gt;
&lt;br /&gt;
For Linux users, there is another option for identifying the “name” and the numbers assigned to each axis and button. Most Linux distributions include a very handy program, “jstest”. With a CH Product Yoke plugged into the system, the following output lines are displayed by jstest: &lt;br /&gt;
&lt;br /&gt;
 jstest /dev/js3 &lt;br /&gt;
 Joystick (CH PRODUCTS CH FLIGHT SIM YOKE USB ) has 7 axes and 12 buttons. Driver version is 2.1.0 &lt;br /&gt;
 Testing…(interrupt to exit) &lt;br /&gt;
 Axes: 0: 0 1: 0 2: 0 3: 0 4: 0 5: 0 6: 0 Buttons: 0:off 1:off 2:off 3:on 4:off 5:off 6:off 7:off 8:off 9:off 10:off 11:off &lt;br /&gt;
&lt;br /&gt;
Note the “name” between parentheses. This is the name the system associates with your joystick. &lt;br /&gt;
&lt;br /&gt;
When you move any control, the numbers change after the axis number corresponding to that moving control and when you depress any button, the “off” after the button number corresponding to the button pressed changes to “on”. In this way, you can quickly write down the axes numbers and button numbers for each function without messing with binary.&lt;br /&gt;
&lt;br /&gt;
=== Writing or editing joystick binding xml files ===&lt;br /&gt;
At this point, you have confirmed that the operating system and the joystick driver both recognize your joystick(s). You also know of several ways to identify the joystick “name” your joystick reports to the driver and operating system. You will need a written list of what control functions you wish to have assigned to which axis and button and the corresponding numbers. &lt;br /&gt;
&lt;br /&gt;
Make the following table from what you learned from js demo or jstest above (pencil and paper is fine). Here we assume there are 5 axes including 2 axes associated with the hat. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot;&lt;br /&gt;
! align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#EFEFEF&amp;quot; | Axis&lt;br /&gt;
! align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#EFEFEF&amp;quot; | Button&lt;br /&gt;
|- &lt;br /&gt;
|elevator = 0 &lt;br /&gt;
|view cycle = 0  &lt;br /&gt;
|- &lt;br /&gt;
|rudder = 1  &lt;br /&gt;
|all brakes = 1  &lt;br /&gt;
|- &lt;br /&gt;
|aileron = 2  &lt;br /&gt;
|up trim = 2  &lt;br /&gt;
|- &lt;br /&gt;
|throttle = 3  &lt;br /&gt;
|down trim = 3  &lt;br /&gt;
|-&lt;br /&gt;
|leftright hat = 4 &lt;br /&gt;
|extend flaps = 4 &lt;br /&gt;
|- &lt;br /&gt;
|foreaft hat = 5  &lt;br /&gt;
|retract flaps = 5 &lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
|decrease RPM = 6 &lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
|increase RPM = 7 &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
We will assume that our hypothetical joystick supplies the “name” QUICK STICK 3D USB to the system and driver. With all the examples included with FlightGear, the easiest way to get a so far unsupported joystick to be auto detected, is to edit an existing binding xml file. Look at the xml files in the sub-folders of '''/FlightGear/Input/Joysticks/'''. After evaluating several of the xml binding files supplied with FlightGear, we decide to edit the file &amp;lt;tt&amp;gt;[[$FG_ROOT]]/Input/Joysticks/Saitek/Cyborg-Gold-3d-USB.xml&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This file has all the axes functions above assigned to axes and all the button functions above assigned to buttons. This makes our editing almost trivial. &lt;br /&gt;
&lt;br /&gt;
Before we begin to edit, we need to choose a name for our bindings xml file, create the folder for the QS joysticks, and copy the original xml file into this directory with this name. &lt;br /&gt;
&lt;br /&gt;
 $ cd /usr/local/FlightGear/Input/Joysticks &lt;br /&gt;
 $ mkdir QS &lt;br /&gt;
 $ cd QS &lt;br /&gt;
 $ cp /usr/local/FlightGear/Input/Joysticks/Saitek/ &lt;br /&gt;
 Cyborg-Gold-3d-USB.xml QuickStick.xml &lt;br /&gt;
&lt;br /&gt;
Here, we obviously have supposed a Linux/UNIX system with FlightGear being installed under '''/usr/local/FlightGear'''. For a similar procedure under Windows with FlightGear being installed under C:/Program Files/FlightGear, open a command shell and type &lt;br /&gt;
&lt;br /&gt;
 C: &lt;br /&gt;
 cd /Program Files/FlightGear/Input/Joysticks &lt;br /&gt;
 mkdir QS &lt;br /&gt;
 cd QS &lt;br /&gt;
 copy /FlightGear/Input/Joysticks/Saitek/ &lt;br /&gt;
 Cyborg-Gold-3d-USB.xml QuickStick.xml &lt;br /&gt;
&lt;br /&gt;
Next, open QuickStick.xml with your favorite editor. Before we forget to change the joystick name, search for the line containing &amp;lt;name&amp;gt;. You should find the line &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;name&amp;gt;SAITEK CYBORG 3D USB&amp;lt;/name&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and change it to &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;name&amp;gt;QUICK STICK 3D USB&amp;lt;/name&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line illustrates a key feature of xml statements. They begin with a &amp;lt;tag&amp;gt; and end with a &amp;lt;/tag&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
You can now compare your table to the comment table at the top of your file copy. Note that the comments tell us that the Saitek elevator was assigned to axis 1. Search for the string &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;axis n=&amp;quot;1&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and change this to &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;axis n=&amp;quot;0&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, note that the Saitek rudder was assigned to axis 2. Search for the string &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;axis n=&amp;quot;2&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
and change this to &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;axis n=&amp;quot;1&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Continue comparing your table with the comment table for the Saitek and changing the axis numbers and button numbers accordingly. Since QUICKSTICK USB and the Saitek have the same number of axes but different number of buttons, you must delete the buttons left over. Just remember to double check that you have a closing tag for each opening tag or you will get an error using the file. &lt;br /&gt;
&lt;br /&gt;
Finally, be good to yourself (and others when you submit your new binding file to a FlightGear developers or users archive!), take the time to change the comment table in the edited file to match your changed axis and button assignments. The new comments should match the table you made from the js demo output. Save your edits. &lt;br /&gt;
&lt;br /&gt;
Several users have reported that the numbers of axes and buttons assigned to functions may be different with the same joystick under Windows and Linux. The above procedure should allow one to easily change a binding xml file created for a different operating system for use by their operating system.&lt;br /&gt;
&lt;br /&gt;
=== Telling FlightGear about your new bindings xml file ===&lt;br /&gt;
Before FlightGear can use your new xml file, you need to edit the file &amp;lt;tt&amp;gt;[[$FG_ROOT]]/joysticks.xml&amp;lt;/tt&amp;gt;, adding a line that will include your new file if the “name” you entered between the name tags matches the name supplied to the driver by your joystick. Add the following line to &amp;lt;tt&amp;gt;[[$FG_ROOT]]/joysticks.xml&amp;lt;/tt&amp;gt;: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;js-named include=&amp;quot;Input/Joysticks/QS/QuickStick.xml&amp;quot;/&amp;gt; &lt;br /&gt;
&lt;br /&gt;
You can tell how FlightGear has interpretted your joystick setup by selecting &amp;lt;tt&amp;gt;Help &amp;gt; Joystick Information&amp;lt;/tt&amp;gt; from the menu.&lt;br /&gt;
&lt;br /&gt;
=== Some hints for Windows users ===&lt;br /&gt;
Basically, the procedures described above should work for Windows as well. If your joystick/yoke/pedals work out of the box or if you get it to work using the methods above, fine. Unfortunately there may be a few problems. &lt;br /&gt;
&lt;br /&gt;
The first one concerns users of non-US Windows versions. As stated above, you can get the name of the joystick from the program js demo. If you have a non-US version of Windows and the joystick .xml files named above do not contain that special name, just add it on top of the appropriate file in the style of:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;name&amp;gt;Microsoft-PC-Joysticktreiber&amp;lt;/name&amp;gt; &lt;br /&gt;
&lt;br /&gt;
No new entry in the base joysticks.xml file is required. &lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is one more loophole with Windows joystick support. In case you have two USB devices attached (for instance a yoke plus pedals), there may be cases, where the same driver name is reported twice. In this case, you can get at least the yoke to work by assigning it number 0 (out of 0 and 1), add a line to &amp;lt;tt&amp;gt;[[$FG_ROOT]]/joystick.xml&amp;lt;/tt&amp;gt; like:&lt;br /&gt;
 &amp;lt;js n=&amp;quot;0&amp;quot; include=&amp;quot;Input/Joysticks/Saitek/ST290-Pro.xml&amp;quot;/&amp;gt;&lt;br /&gt;
if you also have pedals (or another joystick), just add more lines, similar to:&lt;br /&gt;
 &amp;lt;js n=&amp;quot;1&amp;quot; include=&amp;quot;Input/Joysticks/Saitek/Pro-Flight-Rudder-Pedals.xml&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For this purpose, rotate the yoke ([[aileron]] control) and observe the output of js demo. If figures in the first group of colons (for device 0) change, assignment is correct. If figures in the second group of colons (for device 1) change, you have to make the yoke the preferred device first. For doing so, enter the Windows “Control panel”, open “Game controllers” and select the “Advanced” button. Here you can select the yoke as the “Preferred” device. Afterward you can check that assignment by running js demo again. The yoke should now control the first group of figures. &lt;br /&gt;
&lt;br /&gt;
== Joystick support via .fgfsrc entries ==&lt;br /&gt;
Fortunately, there is a tool available now, which takes most of the burden from the average user who, maybe, is not that experienced with XML, the language which these files are written in. &lt;br /&gt;
&lt;br /&gt;
For configuring your joystick using this approach, open a command shell (command prompt under windows, to be found under Start|All programs|Accessories). Change to the directory &amp;lt;tt&amp;gt;[[$FG_ROOT]]/bin&amp;lt;/tt&amp;gt; via e.g. (modify to your path) &lt;br /&gt;
&lt;br /&gt;
 cd C:/Program Files/FlightGear/bin&lt;br /&gt;
&lt;br /&gt;
and invoke the tool fgjs via &lt;br /&gt;
&lt;br /&gt;
 ./fgjs --fg-root=[[$FG_ROOT]]&lt;br /&gt;
&lt;br /&gt;
on a UNIX/Linux machine, or via &lt;br /&gt;
&lt;br /&gt;
 fgjs --fg-root=[[$FG_ROOT]]&lt;br /&gt;
&lt;br /&gt;
on a Windows machine. The program will tell you which joysticks, if any, were detected. Now follow the commands given on screen, i.eṁove the axis and press the buttons as required. Be careful, a minor touch already “counts” as a movement. Check the reports on screen. If you feel something went wrong, just re-start the program. &lt;br /&gt;
&lt;br /&gt;
After you are done with all the axis and switches, the directory above will hold a file called fgfsrc.js. If the FlightGear base directory FlightGear does not already contain an options file .fgfsrc (under UNIX)/system.fgfsrc (under Windows) mentioned above, just copy &lt;br /&gt;
&lt;br /&gt;
'''fgfsrc.js''' into '''.fgfsrc''' (UNIX)/'''system.fgfsrc''' (Windows) &lt;br /&gt;
&lt;br /&gt;
and place it into the directory FlightGear base directory FlightGear. In case you already wrote an options file, just open it as well as fgfsrc.js with an editor and copy the entries from fgfsrc.js into .fgfsrc/system.fgfsrc. One hint: The output of fgjs is UNIX formatted. As a result, Windows Editor may not display it the proper way. I suggest getting an editor being able to handle UNIX files as well. My favorite freeware file editor for that purpose, although somewhat dated, is still PFE, to be obtained from http://www.lancs.ac.uk/people/cpaap/pfe/. &lt;br /&gt;
&lt;br /&gt;
The the axis/button assignment of fgjs should, at least, get the axis assignments right, its output may need some tweaking. There may be axes moving the opposite way they should, the dead zones may be too small etc. For instance, I had to change &lt;br /&gt;
&lt;br /&gt;
 –prop:/input/joysticks/js[1]/axis[1]/binding/factor=-1.0 &lt;br /&gt;
&lt;br /&gt;
into &lt;br /&gt;
&lt;br /&gt;
 –prop:/input/joysticks/js[1]/axis[1]/binding/factor=1.0 &lt;br /&gt;
&lt;br /&gt;
(USB CH Flightsim Yoke under Windows XP). Thus, here is a short introduction into the assignments of joystick properties. &lt;br /&gt;
&lt;br /&gt;
Basically, all axes settings are specified via lines having the following structure: &lt;br /&gt;
&lt;br /&gt;
 --prop:/input/joysticks/js[n]/axis[m]/binding/command=property-scale &lt;br /&gt;
 --prop:/input/joysticks/js[n]/axis[m]/binding/property=/controls/steering option&lt;br /&gt;
 --prop:/input/joysticks/js[n]/axis[m]/binding/dead-band=db&lt;br /&gt;
 --prop:/input/joysticks/js[n]/axis[m]/binding/offset=os&lt;br /&gt;
 --prop:/input/joysticks/js[n]/axis[m]/binding/factor=fa&lt;br /&gt;
&lt;br /&gt;
where &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot;&lt;br /&gt;
! align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#EFEFEF&amp;quot; | &lt;br /&gt;
! align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#EFEFEF&amp;quot; | &lt;br /&gt;
|- &lt;br /&gt;
|n&lt;br /&gt;
|number of device (usually starting with 0)  &lt;br /&gt;
|-&lt;br /&gt;
|m&lt;br /&gt;
|number of axis (usually starting with 0)&lt;br /&gt;
|-&lt;br /&gt;
|steering option&lt;br /&gt;
|elevator, aileron, rudder, throttle, mixture, pitch  &lt;br /&gt;
|-&lt;br /&gt;
|dead-band&lt;br /&gt;
|range, within which signals are discarded; useful to avoid jittering for minor yoke movements&lt;br /&gt;
|-&lt;br /&gt;
|offset&lt;br /&gt;
|specifies, if device not centered in its neutral position &lt;br /&gt;
|-&lt;br /&gt;
|factor&lt;br /&gt;
|controls sensitivity of that axis; defaults to +1, with a value of -1 reversing the behavior &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
You should be able to at least get your joystick working along these lines. Concerning all the finer points, for instance, getting the joystick buttons working, John Check has written a very useful README being included in the base package to be found under '''FlightGear/Docs/Readme/Joystick.html'''. In case of any trouble with your input device, it is highly recommended to have a look into this document.&lt;br /&gt;
&lt;br /&gt;
== More about programming joystick XML files ==&lt;br /&gt;
=== General tips ===&lt;br /&gt;
* When testing a new xml file it is best to start FlightGear via a command window (rather than the GUI interface). Any error messages will then be displayed in the terminal. Error messages will give both a message and a line number, helping you pinpoint any errors.&lt;br /&gt;
* Errors can be detected on initial startup or at runtime. Both types of errors will be displayed in the terminal.&lt;br /&gt;
* One of the most common errors is including a character that makes XML choke. Such characters include&amp;lt;br&amp;gt;&amp;amp; &amp;lt; --&amp;lt;br&amp;gt;These characters will cause problems even if simply included in comments or within scripts.&lt;br /&gt;
* If your scripts contain any of these characters, you have to enclose the scripts in &amp;lt;script&amp;gt;&amp;lt;![CDATA[...]]&amp;gt;&amp;lt;/script&amp;gt;. Alternatively, you can 'escape' the characters, ie &amp;quot;&amp;lt;&amp;quot; becomes &amp;quot;&amp;amp;lt;&amp;quot;.&lt;br /&gt;
* Note that as of ver 1.9.1 there appears to be no way to tell FlightGear to reload joystick files at runtime. So to test any changes to your file you must exit FlightGear and re-start, a somewhat time-consuming process.&lt;br /&gt;
* You can find many examples of different ways to program joysticks simply by examining the joystick xml files that are packaged with FlightGear. See the directory FlightGear/data/input/joysticks&lt;br /&gt;
* Many advanced functions can be programmed using the Nasal scripting language. These scripts are enclosed in &amp;lt;script&amp;gt;&amp;lt;/script&amp;gt; tags in the XML file. Helpful:&lt;br /&gt;
** A guide to the [[Nasal scripting language]] in FlightGear &lt;br /&gt;
** [[Nasal FAQ]]&lt;br /&gt;
** [[Howto: Write simple scripts in Nasal]]&lt;br /&gt;
* You can explore the internal property tree to see many variables that can be altered using joystick buttons or axes (File/Browse Internal Properties)&lt;br /&gt;
* You can test bits of Nasal code and do some other useful things using the Nasal Console (Debug/Nasal Console).&lt;br /&gt;
* All Nasal code shares a common namespace, so it's possible to set a variable in one nasal binding, and to read it in another.&lt;br /&gt;
&lt;br /&gt;
=== Useful hints for scripts ===&lt;br /&gt;
Some particularly useful ideas for programming scripts within joystick XML files:&lt;br /&gt;
* getprop and setprop can be used for getting &amp;amp; setting properties from the internal properties tree:&lt;br /&gt;
 var brake = !getprop(&amp;quot;/controls/gear/brake-parking&amp;quot;);&lt;br /&gt;
 setprop(&amp;quot;/controls/gear/brake-parking&amp;quot;, brake);&lt;br /&gt;
* You can also make your own values on the property tree:&lt;br /&gt;
 setprop(&amp;quot;/input/joysticks/js[0]/myjoystick-modifier&amp;quot;, 1);&lt;br /&gt;
 var mod = getprop(&amp;quot;/input/joysticks/js[0]/myjoystick-modifier&amp;quot;);&lt;br /&gt;
* You can print to terminal using the print function. This is very useful for debugging.&lt;br /&gt;
 print(&amp;quot;Just&amp;quot;, &amp;quot; a &amp;quot;, &amp;quot;test&amp;quot;);&lt;br /&gt;
* You can display info in FlightGear via a popup. This is useful for giving the user feedback about changes that may not be obvious via the panel. It can also be useful for debugging. Example:&lt;br /&gt;
&lt;br /&gt;
 gui.popupTip(&amp;quot;Parking Brake ON&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Arguments for gui.popupTip must be strings, so if you want to display other types of variables they should be formatted with something like sprintf:&lt;br /&gt;
&lt;br /&gt;
 gui.popupTip(sprintf(&amp;quot;Elevator trim: %d&amp;quot;, 100 * getprop(&amp;quot;/controls/flight/elevator-trim&amp;quot;)));&lt;br /&gt;
&lt;br /&gt;
Or&lt;br /&gt;
&lt;br /&gt;
 thv = getprop(&amp;quot;/controls/engines/engine[0]/mixture&amp;quot;);&lt;br /&gt;
 gui.popupTip(&amp;quot;Thrust vector &amp;quot; ~ int(thv * 120 - 20));&lt;br /&gt;
&lt;br /&gt;
* You can just start using variables, ie, &lt;br /&gt;
 x = 10;&lt;br /&gt;
&lt;br /&gt;
But [http://wiki.flightgear.org/index.php/Nasal_scripting_language#Variables for various reasons] it is generally better to declare variables with the &amp;quot;var&amp;quot; statement:&lt;br /&gt;
 var x = 10;&lt;br /&gt;
&lt;br /&gt;
Note that &amp;quot;var&amp;quot; creates variables that are local in scope, which may cause problems if you are intending to use a variable globally among all different bindings in your joystick XML file.&lt;br /&gt;
&lt;br /&gt;
* You can include a section of script that runs on startup to initialize variables, create functions, etc. Example:&lt;br /&gt;
 &amp;lt;PropertyList&amp;gt;&lt;br /&gt;
   &amp;lt;name type=&amp;quot;string&amp;quot;&amp;gt;My joystick name&amp;lt;/name&amp;gt;&lt;br /&gt;
   &amp;lt;name type=&amp;quot;string&amp;quot;&amp;gt;My joystick name #2&amp;lt;/name&amp;gt;&lt;br /&gt;
   &amp;lt;nasal&amp;gt;&lt;br /&gt;
     &amp;lt;script&amp;gt;&lt;br /&gt;
        #initialize variables&lt;br /&gt;
        f1 = f2 = 0;&lt;br /&gt;
        left_brake = right_brake = 0;&lt;br /&gt;
        # create a function to be used with all buttons&lt;br /&gt;
        getmod = func { getprop(&amp;quot;/input/joysticks/js[0]/t-flight-hotas-x-modifier&amp;quot; ) }&lt;br /&gt;
     &amp;lt;/script&amp;gt;&lt;br /&gt;
   &amp;lt;/nasal&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Sample code for firing weapons with the joystick is found on the [[Gun Effects]] page.&lt;br /&gt;
&lt;br /&gt;
== Resource ==&lt;br /&gt;
{{Forum|24|Hardware}}&lt;br /&gt;
* [http://www.flightgear.org/Docs/getstart/getstartch3.html#x8-360003.6 The FlightGear Manual]&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
* [http://sourceforge.net/projects/hapticsforfg/ Force Feedback]&lt;br /&gt;
&lt;br /&gt;
[[Category:Hardware]]&lt;br /&gt;
&lt;br /&gt;
[[de:Joystick]]&lt;br /&gt;
[[es:Joystick]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Sikorsky_S76C&amp;diff=24977</id>
		<title>Sikorsky S76C</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Sikorsky_S76C&amp;diff=24977"/>
		<updated>2010-10-30T21:10:38Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Aircraft help */ sentence structure&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{infobox Aircraft&lt;br /&gt;
|image =S76c landed.jpg&lt;br /&gt;
|alt =The Search and rescue livery&lt;br /&gt;
|name =Sikorsky S76C&lt;br /&gt;
|livery =Search and rescue, Black, Green, RAAF&lt;br /&gt;
|type = Helicopter&lt;br /&gt;
|authors = Syd Adams (FDM), Maik Justus (FDM), Wim (performance specs)&lt;br /&gt;
|fdm = yasim&lt;br /&gt;
|status =&lt;br /&gt;
|fgname = &amp;lt;tt&amp;gt;s76c&amp;lt;/tt&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
The '''Sikorsky S76C ''Spirit''''' is a multi-purpose medium-size commercial [[helicopter]]. Mainly used as rescue helicopter, but also often used for transportation and/or tourist sightseeing.&lt;br /&gt;
&lt;br /&gt;
==Variants==&lt;br /&gt;
There are 13 different variants of the S76. Only one is modeled for [[FlightGear]]:&lt;br /&gt;
* '''S-76C++:''' with a [http://www.turbomeca.com/public/turbomeca_v2/html/en/produits/version.php?aid=636&amp;amp;sfid=504&amp;amp;mid=615 Turboméca Arriel 2S2] engine&lt;br /&gt;
&lt;br /&gt;
==Aircraft help==&lt;br /&gt;
The S-76C is capable of [[Howto: Do aerotow over the net|towing]] other planes or helicopters.&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot;&lt;br /&gt;
!Key&lt;br /&gt;
!Function&lt;br /&gt;
|-&lt;br /&gt;
|O&lt;br /&gt;
|Open aerotow hook&lt;br /&gt;
|-&lt;br /&gt;
|o&lt;br /&gt;
|Lock aerotow hook&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Startup===&lt;br /&gt;
'''Warning: Make sure you have set your collective (thrust to full) before you start your engine!'''&lt;br /&gt;
&lt;br /&gt;
==Development status/Issues/Todo==&lt;br /&gt;
'''Outside:'''&lt;br /&gt;
* No animated doors&lt;br /&gt;
&lt;br /&gt;
{{Sikorsky}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Aircraft]]&lt;br /&gt;
[[Category:Helicopters]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Sikorsky_S76C&amp;diff=24976</id>
		<title>Sikorsky S76C</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Sikorsky_S76C&amp;diff=24976"/>
		<updated>2010-10-30T21:08:26Z</updated>

		<summary type="html">&lt;p&gt;Moksha: spelling&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{infobox Aircraft&lt;br /&gt;
|image =S76c landed.jpg&lt;br /&gt;
|alt =The Search and rescue livery&lt;br /&gt;
|name =Sikorsky S76C&lt;br /&gt;
|livery =Search and rescue, Black, Green, RAAF&lt;br /&gt;
|type = Helicopter&lt;br /&gt;
|authors = Syd Adams (FDM), Maik Justus (FDM), Wim (performance specs)&lt;br /&gt;
|fdm = yasim&lt;br /&gt;
|status =&lt;br /&gt;
|fgname = &amp;lt;tt&amp;gt;s76c&amp;lt;/tt&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
The '''Sikorsky S76C ''Spirit''''' is a multi-purpose medium-size commercial [[helicopter]]. Mainly used as rescue helicopter, but also often used for transportation and/or tourist sightseeing.&lt;br /&gt;
&lt;br /&gt;
==Variants==&lt;br /&gt;
There are 13 different variants of the S76. Only one is modeled for [[FlightGear]]:&lt;br /&gt;
* '''S-76C++:''' with a [http://www.turbomeca.com/public/turbomeca_v2/html/en/produits/version.php?aid=636&amp;amp;sfid=504&amp;amp;mid=615 Turboméca Arriel 2S2] engine&lt;br /&gt;
&lt;br /&gt;
==Aircraft help==&lt;br /&gt;
The S-76C is capable to [[Howto: Do aerotow over the net|tow]] other planes or helicopters.&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot;&lt;br /&gt;
!Key&lt;br /&gt;
!Function&lt;br /&gt;
|-&lt;br /&gt;
|O&lt;br /&gt;
|Open aerotow hook&lt;br /&gt;
|-&lt;br /&gt;
|o&lt;br /&gt;
|Lock aerotow hook&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Startup===&lt;br /&gt;
'''Warning: Make sure you have set your collective (thrust to full) before you start your engine!'''&lt;br /&gt;
&lt;br /&gt;
==Development status/Issues/Todo==&lt;br /&gt;
'''Outside:'''&lt;br /&gt;
* No animated doors&lt;br /&gt;
&lt;br /&gt;
{{Sikorsky}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Aircraft]]&lt;br /&gt;
[[Category:Helicopters]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Howto:Be_a_controller&amp;diff=24975</id>
		<title>Howto:Be a controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Howto:Be_a_controller&amp;diff=24975"/>
		<updated>2010-10-30T20:58:48Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Multiplayer setup */ improve sentence structure&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{ATC-navbar}}&lt;br /&gt;
{{Main article|Air traffic control}}&lt;br /&gt;
&lt;br /&gt;
===ATC-aircraft===&lt;br /&gt;
{{Main article|ATC-aircraft}}&lt;br /&gt;
Anyone can be a controller using the UFO or any other plane but to get the real ATC feeling you should use the [[ATC-aircraft]].  The advantage of the ATC-aircraft is that you have a radar, just like in real life. No more looking at the [[MPMap]] to check where the pilots are.&lt;br /&gt;
&lt;br /&gt;
===Multiplayer setup===&lt;br /&gt;
The other pilots must know that you are a controller and which airport you're controlling. For this reason you should use a special call-sign. In the table below you can find the call-signs which are used by the different types of controllers. Since we don't have a lot of controllers at FlightGear, we almost always have to be the tower controller.&lt;br /&gt;
&lt;br /&gt;
Example: For San Francisco you're callsign would be KSFO_TWR, or for London Heathrow it would be EGLL_TWR.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot;&lt;br /&gt;
! align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#EFEFEF&amp;quot; | Position Suffix&lt;br /&gt;
! align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#EFEFEF&amp;quot; | Name&lt;br /&gt;
! align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#EFEFEF&amp;quot; | Description&lt;br /&gt;
|- &lt;br /&gt;
| xxxx_GND &lt;br /&gt;
|Ground Controller&lt;br /&gt;
|Controls the movement of aircraft on the ground at an airport, however only the taxiways and bays... not the active runways. Whenever a plane needs to cross an active runway, it must call the tower.&lt;br /&gt;
|-&lt;br /&gt;
| bgcolor=&amp;quot;#EFEFEF&amp;quot; align=&amp;quot;left&amp;quot; |xxxx_TWR&lt;br /&gt;
| bgcolor=&amp;quot;#EFEFEF&amp;quot; align=&amp;quot;left&amp;quot; |Tower Controller&lt;br /&gt;
| bgcolor=&amp;quot;#EFEFEF&amp;quot; align=&amp;quot;left&amp;quot; |'Owns' the runways and the airspace up to 10 NM (nautical miles) from the airport. Clears planes for takeoff and landing.&lt;br /&gt;
|-&lt;br /&gt;
|xxxx_APP&lt;br /&gt;
|Approach Controller&lt;br /&gt;
|Controls the airspace up to 30NM away from the airport, up to 18,000 ft (usually). Handles all aircraft leaving or arriving at an airport, until they are established on the ILS (then hands the flight off  to TWR) or are leaving their airspace to continue flight (then hands off to CTR)&lt;br /&gt;
|-&lt;br /&gt;
| bgcolor=&amp;quot;#EFEFEF&amp;quot; align=&amp;quot;left&amp;quot; |xxxx_DEP&lt;br /&gt;
| bgcolor=&amp;quot;#EFEFEF&amp;quot; align=&amp;quot;left&amp;quot; |Departure Controller &lt;br /&gt;
| bgcolor=&amp;quot;#EFEFEF&amp;quot; align=&amp;quot;left&amp;quot; |This position is rarely used except at busy airports in the real world which relieves the work-load of the approach controller by handling all the departures, and getting them away from arrivals as quickly as possible, leaving the approach controller free to handle arrivals (the hard bit).&lt;br /&gt;
|-&lt;br /&gt;
|xxxx_CTR&lt;br /&gt;
|(ARTCC) Center Controller&lt;br /&gt;
|Centers own all airspace not controlled by APP or TWR. They control the plane while en route, and get it from X to Y safely, until it can be descended and given to the approach controller.&lt;br /&gt;
|-&lt;br /&gt;
| bgcolor=&amp;quot;#EFEFEF&amp;quot; align=&amp;quot;left&amp;quot; |xxxx_FSS&lt;br /&gt;
| bgcolor=&amp;quot;#EFEFEF&amp;quot; align=&amp;quot;left&amp;quot; |Flight Service Station&lt;br /&gt;
| bgcolor=&amp;quot;#EFEFEF&amp;quot; align=&amp;quot;left&amp;quot; |Flight Service Stations cover large areas  (e.g.: France) and provide support to pilots and controllers. They can advise pilots of weather and frequencies for other controllers. They do not provide Air Traffic Control.&lt;br /&gt;
|-&lt;br /&gt;
|xxxx_DEL&lt;br /&gt;
|Clearance Delivery&lt;br /&gt;
|Clearance Delivery is rarely used in FlightSims. In the real world, a controller would give a clearance (which explains where the plane is allowed to fly) to all planes, but the ease of giving a clearance in the virtual world, means the Tower can normally give the clearance.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Airport diagram===&lt;br /&gt;
After the multiplayer settings have been set, a diagram of the airport should be downloaded. The diagram shows the names of the taxiways, directions of the runways, and locations of the gates, etc. So the airport diagram is very important for a controller!&lt;br /&gt;
&lt;br /&gt;
The best way to find an airport diagram is by searching Google for xxxx Diagram. For KSFO we search for &amp;lt;tt&amp;gt;KSFO Diagram&amp;lt;/tt&amp;gt;, first hit is already what we need. Most of the countries have their own databases with diagrams. It's worth it to take a look at them, because they often provide better and more detailed diagrams.&lt;br /&gt;
&lt;br /&gt;
You can print out the diagram and put it beside your computer. This way you don't have to switch screens to look at the diagram.&lt;br /&gt;
&lt;br /&gt;
[[Image:ATC-aircraft.jpg|thumb|270px|The panel (with radar) as found when using the [[ATC-aircraft]].]]&lt;br /&gt;
&lt;br /&gt;
===Controlling===&lt;br /&gt;
Now we're finally ready to control. Launch FlightGear with the multiplayer settings we set above. After FG has loaded you'll find yourself in the tower. You're screen should look like the picture shown on the right. The large black sqaure with green and white texts is your radarscreen. Each dot is a pilot. Beside the dot you find some information about the aircraft (like altitude, speed and heading). &lt;br /&gt;
* Click on the triangles on either side of &amp;lt;tt&amp;gt;No #&amp;lt;/tt&amp;gt; to select planes within the set range of the radar. The selected plane is highlighted in white on your radar screen. At the same time you see the information of the selected plane appear in the boxes below the radar.&lt;br /&gt;
* To increase the range of the radar (to see more airspace) click on the triangles near &amp;lt;tt&amp;gt;Range&amp;lt;/tt&amp;gt;. You can only select planes that are within the set range of the radar.&lt;br /&gt;
* The large bar at the lower part of the screen is used to compose chat messages. You must click the send button to send your message.&lt;br /&gt;
&lt;br /&gt;
''See [[ATC Tutorial]]''&lt;br /&gt;
&lt;br /&gt;
==Problems and solutions==&lt;br /&gt;
* Why do I see a lot of planes which aren't shown on the MPMap?&lt;br /&gt;
** These planes are [[AI-traffic]], which isn't showed on the MPMap. To turn AI-traffic off, use the following property: &amp;lt;tt&amp;gt;/sim/traffic-manager/enabled=false&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* How could I change the COM frequencies?&lt;br /&gt;
** Go to &amp;lt;tt&amp;gt;Equipment &amp;gt; Radio settings&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Air Traffic Control]]&lt;br /&gt;
[[Category:Howto|Be a controller]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=FSweekend_2010&amp;diff=24974</id>
		<title>FSweekend 2010</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=FSweekend_2010&amp;diff=24974"/>
		<updated>2010-10-30T20:53:08Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Booth information */spelling&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:FSweekend_banner_2010.jpg|right|350px]]&lt;br /&gt;
This wiki page lists all information required for participants to the [[FSweekend]] and the attached multiplayer event(s). [[FlightGear]] will be represented by a team of seven regular FlightGear developers and users.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;eventcountdown date=&amp;quot;06-November-2010&amp;quot;&amp;gt;'''&amp;lt;daysuntil in=&amp;quot;days&amp;quot;&amp;gt;06-November-2010&amp;lt;/daysuntil&amp;gt;''' until the FSweekend&amp;lt;/eventcountdown&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Booth information==&lt;br /&gt;
This year's booth will probably exist of:&lt;br /&gt;
[[image:Anaglyph-glasses.jpg|right]]&lt;br /&gt;
* an UMTS USB stick for unlimited data use at high speed, so users from all over the world can visit us virtually.&lt;br /&gt;
* a bunch of 3D glasses, to demo the [[Anaglyph (3D)|anaglyph]] ability of FlightGear.&lt;br /&gt;
* a FlightGear based [[Howto:_Build_your_own_procedure_trainer|procedure trainer]].&lt;br /&gt;
* a Linux-based triple-screen PC, with a generic set of input devices for general purpose flight demonstrations. &lt;br /&gt;
* a top-end workstation equipped with 4(!) nVidia GTX460 to showcase our multi-screen capabilities&lt;br /&gt;
&lt;br /&gt;
=== Equipment Checklist ===&lt;br /&gt;
* One main power extension cord (DT: yellow)&lt;br /&gt;
* One main power extension cord (DT: green)&lt;br /&gt;
* One main power extension cord (TD: black)&lt;br /&gt;
* One main power extension cord (JVDV: red)&lt;br /&gt;
* One Linux-based PC (DT) &lt;br /&gt;
** Three monitors&lt;br /&gt;
** Saitek Joystick &lt;br /&gt;
** Saitek Rudder Pedals&lt;br /&gt;
** Headset&lt;br /&gt;
** Sound system&lt;br /&gt;
* One Linux-based PC (JVDV) &lt;br /&gt;
** Three monitors&lt;br /&gt;
** Thrustmaster HOTAS Cougar&lt;br /&gt;
** Saitek Rudder Pedals&lt;br /&gt;
** USB Headset&lt;br /&gt;
* One Macbook Pro (DT) &lt;br /&gt;
** simple joystick&lt;br /&gt;
* One Macbook, white (TD)&lt;br /&gt;
* One Linx-based Notebook (TD)&lt;br /&gt;
** simple joystick&lt;br /&gt;
** ELITE yoke&lt;br /&gt;
** simple, homemade multi-engine and view controller&lt;br /&gt;
** 3Dconnexion 3d-mouse&lt;br /&gt;
* One FlightGear based procedure trainer (TD) [[image:Pmpt-0.1.jpg|right|thumb]]&lt;br /&gt;
** ELITE ProPanelII&lt;br /&gt;
** FlightLink rudder set&lt;br /&gt;
** Two TFT Displays&lt;br /&gt;
** Panel controller&lt;br /&gt;
** old (historic?) tablet pc running Atlas&lt;br /&gt;
* One Thomas-Krens-AG workstation (TD)&lt;br /&gt;
** Eight monitors (probably)&lt;br /&gt;
* Two FlightGear banners (TD)&lt;br /&gt;
** mounting material (last year's setup from Durk)&lt;br /&gt;
* FlightGear business cards (TD)&lt;br /&gt;
* Coffee maker (Senseo, bring your own pads!) (TD)&lt;br /&gt;
* two or three sets of aviation headsets (deco) (TD)&lt;br /&gt;
* One CH Flight Sim Yoke&lt;br /&gt;
* One CH Pro Pedals&lt;br /&gt;
&lt;br /&gt;
==Flight information==&lt;br /&gt;
===Airports===&lt;br /&gt;
Activities will mainly take place at and around [[Amsterdam Airport Schiphol]] (EHAM), [[Lelystad Airport]] (EHLE), [[Volkel Air Base]] (EHVK) and the VU University Medical Center Helipad [[EH0001]].&lt;br /&gt;
&lt;br /&gt;
===Charts===&lt;br /&gt;
All charts that you may have to use on your flights are available at http://ais-netherlands.nl (AIS Publications &amp;gt; Integrated Package). Please note that these are the most up to date charts available, so certain situations might not have been changed in FlightGear (EHAM, EHLE and EHVK taxiways should be correct though).&lt;br /&gt;
&lt;br /&gt;
Parking positions have been created for most of the Dutch airports including EHAM, EHRD, EHVK and EHLE (A1-A6, B1 and B2).&lt;br /&gt;
&lt;br /&gt;
All named airports are for civil usage, except for [[Volkel Air Base]] (EHVK). This base will be occupied by the (AI) F-16 squadrons and likely one setup in Lelystad. Feel free to join with your F-16 or other Dutch/NATO mil aircraft.&lt;br /&gt;
&lt;br /&gt;
===Weather information===&lt;br /&gt;
Reallife weather information can be found at the KNMI (Dutch Meteorological institute) website.&lt;br /&gt;
* [http://knmi.nl/actueel/metar.html METAR] current weather at airports&lt;br /&gt;
* [http://knmi.nl/waarschuwingen_en_verwachtingen/luchtvaart/nederlandse_vliegveldverwachtingen.html TAF] expected weather at airports&lt;br /&gt;
If the weather is really bad, it is likely that the FSweekend guys will use a preset weather scenario.&lt;br /&gt;
&lt;br /&gt;
==Scenery==&lt;br /&gt;
We will be using newly generated scenery in Lelystad.&lt;br /&gt;
&lt;br /&gt;
==Events==&lt;br /&gt;
The guys from [[TransGear]] will organise a multiplayer event on both days. The event consist pilots flying pre-requested routes from and to Schiphol (EHAM). All activity at EHAM will take place around 13:00 GMT (that is 14:00 local time in the Netherlands). Traffic will be controlled by at least one (likely more) air traffic controller(s).&lt;br /&gt;
&lt;br /&gt;
The people in Lelystad will have something to show to the public and might be able to participate during parts of the event (maybe there are even some visitors to our booth that would like to fly in one of our best MP events).&lt;br /&gt;
&lt;br /&gt;
More information in the [http://flightgear.org/forums/viewtopic.php?f=10&amp;amp;t=9773 forum topic] and on the [http://transgear.treborlogic.com/ TransGear website].&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Piper_PA34-200T_Seneca_II&amp;diff=24973</id>
		<title>Piper PA34-200T Seneca II</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Piper_PA34-200T_Seneca_II&amp;diff=24973"/>
		<updated>2010-10-30T20:45:59Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Introduction */ sentence structure&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{infobox Aircraft&lt;br /&gt;
|image =Piper_SenecaII.jpg&lt;br /&gt;
|name =Piper PA34-200T Seneca II&lt;br /&gt;
|type =Civilian aircraft&lt;br /&gt;
|fdm =JSBSim&lt;br /&gt;
|status =early-production&lt;br /&gt;
|authors =Torsten Dreyer&lt;br /&gt;
|fgname =&amp;lt;tt&amp;gt;SenecaII-jsbsim&amp;lt;/tt&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
[[Image:SenecaII_real.jpg|thumb|250px|The real Seneca II]]&lt;br /&gt;
This is a model of a Piper PA34-200T Seneneca II. The Seneca has been made by Piper since the early 1970's and some 4500 were made since then. It has six seats in a pretty large cabin, two turbocharged counterrotating engines producing 200hp up to 12,000 ft. It cruises at 170ktas in 12,000ft at 65% power. Certification for flights into known icing conditions and the nice single engine behaviour made the Seneca a popular multi engine trainer.&lt;br /&gt;
&lt;br /&gt;
The model was built using the  Pilots Operating Handbook, a real Seneca (D-GEJL) and some flight performance data derived in real flights.&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot; /&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
=== Full functional 3d cockpit ===&lt;br /&gt;
[[Image:SenecaII_cockpit.jpg|thumb|250px|The 3d cockpit]]&lt;br /&gt;
Almost all controls, switches, gauges and indicators are implemented and functional in the cockpit. For description of the panel have a look at the [[Seneca II Panel Reference]].&lt;br /&gt;
The default KI227 ADF indicator can be exchanged into a KI228 RMI indicator coupled to ADF and NAV1 radio.&lt;br /&gt;
To use the KI228, simply set the property &lt;br /&gt;
 /instrumentation/adf/model&lt;br /&gt;
to&lt;br /&gt;
 ki228&lt;br /&gt;
in the property browser or use the command line switch&lt;br /&gt;
 --prop://instrumentation/adf/model=ki228&lt;br /&gt;
when starting up the Seneca&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Using the menu items ''Help-&amp;gt;Start Tutorial'' a bunch of tutorials are reachable. &lt;br /&gt;
* '''Cold Start''' Puts your aircraft into hibernation mode. Everything is off.&lt;br /&gt;
* '''Hot Start''' Everything is ready to go, just start the engines and fly.&lt;br /&gt;
* * '''Check''' These are the checklists from [[Seneca II Checklist]]&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Structural Icing ===&lt;br /&gt;
[[Image:SenecaII_icing.jpg|thumb|250px|Icing on the temperature probe]]&lt;br /&gt;
Since the Seneca provides anti- and deice equipment, I tried to model structural icing into flightgear. A little nasal script does most of the work: First it reads the property nodes under /sim/model/icing where any number of iceable elements configure the ice sensitive elements of the aircraft. Each element have a name, a sensitivity to icing, may have a salvage control and the name of a output property where the collected amount of ice is written to. After the initial configuration, a timed loop is executed every 2 seconds. It&lt;br /&gt;
* calculates the spread by OAT and dewpoint&lt;br /&gt;
* checks visibility (see remark) to tell if the aircraft is within clouds&lt;br /&gt;
* if the spread is below 0.1 degc and visibility is below 1000m, assumes potential icing condition and icing severity is calculated&lt;br /&gt;
* update all ice sensitive elements with the current icing conditions&lt;br /&gt;
&lt;br /&gt;
The icing severities are defined as&lt;br /&gt;
{|&lt;br /&gt;
! severity&lt;br /&gt;
! inches&lt;br /&gt;
! per NM (still air)&lt;br /&gt;
|-&lt;br /&gt;
| NONE&lt;br /&gt;
| -0.3&lt;br /&gt;
| 80&lt;br /&gt;
|-&lt;br /&gt;
| TRACE&lt;br /&gt;
| 0.5&lt;br /&gt;
| 80&lt;br /&gt;
|-&lt;br /&gt;
| LIGHT&lt;br /&gt;
| 0.5&lt;br /&gt;
| 40&lt;br /&gt;
|-&lt;br /&gt;
| MODERATE&lt;br /&gt;
| 0.5&lt;br /&gt;
| 20&lt;br /&gt;
|-&lt;br /&gt;
| SEVERE&lt;br /&gt;
| 0.5&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The rule for calculating the severity is&lt;br /&gt;
{|&lt;br /&gt;
! OAT_min&lt;br /&gt;
! OAT_max&lt;br /&gt;
! severity_min&lt;br /&gt;
! severity_max&lt;br /&gt;
|-&lt;br /&gt;
| -99&lt;br /&gt;
| -30&lt;br /&gt;
| NONE&lt;br /&gt;
| TRACE&lt;br /&gt;
|-&lt;br /&gt;
| -30&lt;br /&gt;
| -20&lt;br /&gt;
| TRACE&lt;br /&gt;
| LIGHT&lt;br /&gt;
|-&lt;br /&gt;
| -20&lt;br /&gt;
| -12&lt;br /&gt;
| LIGHT&lt;br /&gt;
| SEVERE&lt;br /&gt;
|-&lt;br /&gt;
| -2&lt;br /&gt;
| -0&lt;br /&gt;
| NONE&lt;br /&gt;
| MODERATE&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 999&lt;br /&gt;
| NONE&lt;br /&gt;
| NONE&lt;br /&gt;
|}&lt;br /&gt;
When oat is above zero degc, Ice melts at a rate of 0.5&amp;quot; per 10NM at 10degc, the warmer the faster.&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Pitot Icing ===&lt;br /&gt;
The pitot tube is prone to icing, too. A little agent is waiting for you to get into icing conditions without switching on the pitot heat. If he gets you, he will fail your pitot system which will result in some strange airspeed indicator behaviour.&lt;br /&gt;
&lt;br /&gt;
== Pilot Operating Handbook ==&lt;br /&gt;
=== General ===&lt;br /&gt;
==== Engines ====&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; | Number of Engines&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
|Engine Manufacturer&lt;br /&gt;
|Continental&lt;br /&gt;
|-&lt;br /&gt;
|Engine Model Number&lt;br /&gt;
|(L)TSIO-360EB&lt;br /&gt;
|-&lt;br /&gt;
|Rated Horsepower&lt;br /&gt;
|Sea Level: 200, 12,000ft.: 215&lt;br /&gt;
|-&lt;br /&gt;
|Rated Speed (rpm)&lt;br /&gt;
|2575&lt;br /&gt;
|-&lt;br /&gt;
|Bore (inches)&lt;br /&gt;
|4.438&lt;br /&gt;
|-&lt;br /&gt;
|Stroke (inches)&lt;br /&gt;
|3.875&lt;br /&gt;
|-&lt;br /&gt;
|Displacement (cubic inches)&lt;br /&gt;
|360&lt;br /&gt;
|-&lt;br /&gt;
|Compression Ratio&lt;br /&gt;
|7.5:1&lt;br /&gt;
|-&lt;br /&gt;
|Engine Type&lt;br /&gt;
| Six Cylinder, Direct Drive, Horizontally Opposed, Air Cooled&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Propellers ====&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; |Number of Propellers&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; |2&lt;br /&gt;
|-&lt;br /&gt;
|Propeller Manufacturer&lt;br /&gt;
|Hartzell&lt;br /&gt;
|-&lt;br /&gt;
|Number of Blades&lt;br /&gt;
|2&lt;br /&gt;
|-&lt;br /&gt;
|Propeller Diameter&lt;br /&gt;
| Maximum: 76 inches, Minimum: 75 inches&lt;br /&gt;
|-&lt;br /&gt;
|Propeller Type&lt;br /&gt;
|Constant Speed, Hydraulically Actuated, Full Feathering&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Fuel ====&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; |Fuel Capacity (U.S.gal) (total)&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; |128&lt;br /&gt;
|-&lt;br /&gt;
|Usable Fuel (U.S.gal) (total)&lt;br /&gt;
|123&lt;br /&gt;
|-&lt;br /&gt;
|Minumum Grade&lt;br /&gt;
|100 Green or 100LL Blue Aviation Grade&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Oil ====&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; |Oil Capacity (U.S.quarts) (per engine)&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; |8&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Maximum Weights ====&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; |Maximum Takeoff Weight (lbs)&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; |4570&lt;br /&gt;
|-&lt;br /&gt;
|Maximum Landing Weight (lbs)&lt;br /&gt;
|4362&lt;br /&gt;
|-&lt;br /&gt;
|Maximum Zero Fuel Weight (lbs) - Standard&lt;br /&gt;
|4000&lt;br /&gt;
|-&lt;br /&gt;
|Maximum Weight in Baggage Compartment (lbs)&lt;br /&gt;
|Forward: 100, Aft: 100&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Standard Airplane Weights ====&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; | Standard Empty Weight (lbs): Weight of a standard airplane including unusable fuel, full operating fluids and full oil.&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; | 2823&lt;br /&gt;
|-&lt;br /&gt;
| Maximum Useful Load (lbs): The difference between the Maximum Takeoff Weight and the Standard Empty Weight. (All weight in excess off 4000lbs must consist of fuel)&lt;br /&gt;
|1747&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Specific Loadings ====&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; | Wing Loading (lbs per sq ft)&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; | 22&lt;br /&gt;
|- &lt;br /&gt;
| Power Loading (lbs per hp)&lt;br /&gt;
| Sea Level: 11.4 - 12,000ft: 10.6&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Limitations ===&lt;br /&gt;
==== Airspeed Limitations ====&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
! width=&amp;quot;50%&amp;quot; align=&amp;quot;left&amp;quot; | Speed&lt;br /&gt;
! width=&amp;quot;25%&amp;quot; align=&amp;quot;left&amp;quot; | KIAS&lt;br /&gt;
! width=&amp;quot;25%&amp;quot; align=&amp;quot;left&amp;quot; | KCAS&lt;br /&gt;
|-&lt;br /&gt;
| Never Exceed Speed (V&amp;lt;sub&amp;gt;NE&amp;lt;/sub&amp;gt;) - Do not exceed this speed in any operation&lt;br /&gt;
| 195&lt;br /&gt;
| 195&lt;br /&gt;
|-&lt;br /&gt;
| Maximum Structural Cruising Speed (V&amp;lt;sub&amp;gt;NO&amp;lt;/sub&amp;gt;) - Do not exceed this speed except in smooth air and then only with caution.&lt;br /&gt;
| 163&lt;br /&gt;
| 165&lt;br /&gt;
|-&lt;br /&gt;
| Design Maneuvering Speed (V&amp;lt;sub&amp;gt;A&amp;lt;/sub&amp;gt;) - Do not make full or abrupt control movements above this speed.&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot;| At 4570 LBS G.W.&lt;br /&gt;
| 136&lt;br /&gt;
| 138&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot;|At 3068 LBS G.W.&lt;br /&gt;
| 121&lt;br /&gt;
| 122&lt;br /&gt;
|-&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; |&lt;br /&gt;
&amp;lt;b&amp;gt;CAUTION&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Maneuvering speed decreases at lighter weight as the effects of aerodynamic forces become more pronounced. Linear interpolation may be used for imtermediate gross weights. maneuvering speed should not be exceeded while operating in rough air.&lt;br /&gt;
|-&lt;br /&gt;
| Maximum Flaps Extended Speed (V&amp;lt;sub&amp;gt;FE&amp;lt;/sub&amp;gt;) - Do not exceed this speed with flaps extended.&lt;br /&gt;
| 107&lt;br /&gt;
| 109&lt;br /&gt;
|-&lt;br /&gt;
| Maximum Gear Extended Speed (V&amp;lt;sub&amp;gt;LE&amp;lt;/sub&amp;gt;) - Do not exceed this speed with landing gear extended&lt;br /&gt;
| 129&lt;br /&gt;
| 130&lt;br /&gt;
|-&lt;br /&gt;
| Maximum Landing Gear Extending Speed (V&amp;lt;sub&amp;gt;LO&amp;lt;/sub&amp;gt;) - Do not extend landing gear above this speed&lt;br /&gt;
| 129&lt;br /&gt;
| 130&lt;br /&gt;
|-&lt;br /&gt;
| Maximum Landing Gear Retracting Speed (V&amp;lt;sub&amp;gt;LO&amp;lt;/sub&amp;gt;) - Do not retract landing gear above this speed&lt;br /&gt;
| 107&lt;br /&gt;
| 109&lt;br /&gt;
|-&lt;br /&gt;
| Air Minimum Control Speed (V&amp;lt;sub&amp;gt;MC&amp;lt;/sub&amp;gt;) - Lowes airspeed at which airplane is controllable with one engine operating and no flaps&lt;br /&gt;
| 66&lt;br /&gt;
| 69&lt;br /&gt;
|-&lt;br /&gt;
| Best Single Engine Rate of Climb Speed&lt;br /&gt;
| 89&lt;br /&gt;
| 90&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Airspeed Indicator Markings ====&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
! width=&amp;quot;50%&amp;quot; align=&amp;quot;left&amp;quot; | Marking&lt;br /&gt;
! width=&amp;quot;50%&amp;quot; align=&amp;quot;left&amp;quot; | KIAS&lt;br /&gt;
|- &lt;br /&gt;
|Green Arc (Normal Operating Range)&lt;br /&gt;
|63 to 163&lt;br /&gt;
|- &lt;br /&gt;
|Yellow Arc (Caution Range - Smooth Air)&lt;br /&gt;
|163 to 195&lt;br /&gt;
|-&lt;br /&gt;
|White Arc (Flaps Extended Range)&lt;br /&gt;
|61 to 107&lt;br /&gt;
|-&lt;br /&gt;
|Radial Red Line (Never Exceed - Smooth Air)&lt;br /&gt;
|195&lt;br /&gt;
|-&lt;br /&gt;
|Radial Red Line (Minimum Control Speed - Single Engine)&lt;br /&gt;
|66&lt;br /&gt;
|-&lt;br /&gt;
|Radial Blue Line (Best Rate of Climb Speed - Single Engine)&lt;br /&gt;
|89&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Power Plant Limitations ====&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; | Maximum Rotational Speed&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; | 2575&lt;br /&gt;
|- &lt;br /&gt;
| Maximum Manifold Pressure (Inches of Mercury)&lt;br /&gt;
| 40&lt;br /&gt;
|- &lt;br /&gt;
| Maximum Cylinder Head Temperature&lt;br /&gt;
| 460 &amp;amp;deg;F&lt;br /&gt;
|-&lt;br /&gt;
| Maximum Oil Temperature&lt;br /&gt;
| 240 &amp;amp;deg;F&lt;br /&gt;
|-&lt;br /&gt;
| Minimum Oil Pressure (red line)&lt;br /&gt;
| 10 PSI&lt;br /&gt;
|-&lt;br /&gt;
| Maximum Oil Pressure (red line)&lt;br /&gt;
| 100 PSI&lt;br /&gt;
|-&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | &lt;br /&gt;
&amp;lt;b&amp;gt;NOTES&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Avoid continuous operation between 2000 and 2000 RPM  above 32 IN. HG. manifold pressure.&lt;br /&gt;
&lt;br /&gt;
Avoid continuous ground operation between 1700 and 2100 RPM in cross and tail winds over 10 knots.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Power Plant Instrument Markings ====&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
! width=&amp;quot;50%&amp;quot; align=&amp;quot;left&amp;quot;| Tachometer&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; | &amp;amp;nbsp;&lt;br /&gt;
|- &lt;br /&gt;
| Green Arc (Normal Operating Range)&lt;br /&gt;
| 500 RPM to 2575 RPM&lt;br /&gt;
|- &lt;br /&gt;
| Red Line (Maximum)&lt;br /&gt;
| 2575 RPM&lt;br /&gt;
|-&lt;br /&gt;
! align=&amp;quot;left&amp;quot; | Fuel Flow and Pressure&lt;br /&gt;
|&amp;amp;nbsp;&lt;br /&gt;
|-&lt;br /&gt;
| Green Arc (Normal Operating Range)&lt;br /&gt;
| 3.5 PSI to 20 PSI&lt;br /&gt;
|-&lt;br /&gt;
| Red Line (Maximum at Sea Level)&lt;br /&gt;
| 25 GPH (20PSI)&lt;br /&gt;
|-&lt;br /&gt;
| Red Line (Minimum)&lt;br /&gt;
| 3.5 PSI&lt;br /&gt;
|-&lt;br /&gt;
! align=&amp;quot;left&amp;quot; | Cylinder Head Temperature&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
|-&lt;br /&gt;
| Green Arc (Normal Range)&lt;br /&gt;
| either 360 &amp;amp;deg;F to 460 &amp;amp;deg;F&lt;br /&gt;
|-&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
| or 240 &amp;amp;deg;F to 460 &amp;amp;deg;F&lt;br /&gt;
|-&lt;br /&gt;
| Red Line (Maximum)&lt;br /&gt;
| 460 &amp;amp;deg;F&lt;br /&gt;
|-&lt;br /&gt;
! align=&amp;quot;left&amp;quot; | Oil Temperature&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
|-&lt;br /&gt;
| Green Arc (Normal Operating Range)&lt;br /&gt;
| either 75 &amp;amp;deg;F to 240 &amp;amp;deg;F&lt;br /&gt;
|-&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
| or 100 &amp;amp;deg;F to 240 &amp;amp;deg;F&lt;br /&gt;
|-&lt;br /&gt;
| Red Line (Maximum)&lt;br /&gt;
| 240 &amp;amp;deg;F&lt;br /&gt;
|-&lt;br /&gt;
! align=&amp;quot;left&amp;quot; | Oil Pressure&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
|-&lt;br /&gt;
| Green Arc (Normal Operating Range)&lt;br /&gt;
| either 30 PSI to 80 PSI&lt;br /&gt;
|-&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
| or 30 PSI to 60 PSI&lt;br /&gt;
|-&lt;br /&gt;
| Yellow Arc (Caution)&lt;br /&gt;
| either 80 PSI to 100 PSI&lt;br /&gt;
|-&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
| or 60 PSI to 100 PSI&lt;br /&gt;
|-&lt;br /&gt;
| Red Line (Minimum)&lt;br /&gt;
| 10 PSI&lt;br /&gt;
|-&lt;br /&gt;
| Red Line (Maximum)&lt;br /&gt;
| 100 PSI&lt;br /&gt;
|-&lt;br /&gt;
! align=&amp;quot;left&amp;quot; | Manifold Pressure&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
|-&lt;br /&gt;
| Green Arc (Normal Operating Range)&lt;br /&gt;
| 10 IN. to 40 IN. HG.&lt;br /&gt;
|-&lt;br /&gt;
| Red Line (Maximum)&lt;br /&gt;
| 40 IN. HG.&lt;br /&gt;
|-&lt;br /&gt;
! align=&amp;quot;left&amp;quot; | Exhaust Gas Temperature&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
|-&lt;br /&gt;
| Red Line&lt;br /&gt;
| 1650 &amp;amp;deg;F&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Center of Gravity Limits ====&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
! width=&amp;quot;33%&amp;quot; align=&amp;quot;left&amp;quot; | Weight&amp;lt;br&amp;gt;Ponds&lt;br /&gt;
! width=&amp;quot;33%&amp;quot; align=&amp;quot;left&amp;quot;| Forward Limit&amp;lt;br&amp;gt;Inches Aft of Datum&lt;br /&gt;
! width=&amp;quot;34%&amp;quot; align=&amp;quot;left&amp;quot; | Aft Limit&amp;lt;br&amp;gt;Inches Aft of Datum&lt;br /&gt;
|-&lt;br /&gt;
|3400&lt;br /&gt;
|82.0&lt;br /&gt;
|94.6&lt;br /&gt;
|-&lt;br /&gt;
|4570&lt;br /&gt;
|90.6&lt;br /&gt;
|94.6&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;b&amp;gt;NOTES&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Straight line variation between the points given.&lt;br /&gt;
&lt;br /&gt;
Datum is 78.4 inches forward of wing leading edge from the inboard edge of the inboard fuel tank.&lt;br /&gt;
&lt;br /&gt;
==== Maneuver Limits ====&lt;br /&gt;
All intentional acrobatic maneuvers (including spins) are prohibited. Avoid abrupt maneuvers.&lt;br /&gt;
&lt;br /&gt;
==== Flight Load Factor Limits ====&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; | Positive Load Factor (Maximum)&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; | 3.8 G&lt;br /&gt;
|-&lt;br /&gt;
| Negative Load Factor (Maximum)&lt;br /&gt;
| No inverted maneuvers approved&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Types of Operations ====&lt;br /&gt;
The airplane is approved for the following operations when equipped in accordance with FAR 91 or FAR 135&lt;br /&gt;
* Day VFR&lt;br /&gt;
* Night VFR&lt;br /&gt;
* Day IFR&lt;br /&gt;
* Night IFR&lt;br /&gt;
* Icing conditions when equipped.&lt;br /&gt;
&lt;br /&gt;
==== Fuel Limitations ====&lt;br /&gt;
The usable fuel in this aircraft is 61.5 gallons in each wing or a total of 123 gallons.&lt;br /&gt;
&lt;br /&gt;
==== Gyro Pressure Limits ====&lt;br /&gt;
The operating limits for the pressure system are 4.5 to 5.2 inches of mercury for all operations as indicated by the gyro pressure gauge.&lt;br /&gt;
&lt;br /&gt;
==== Flight Into Known Icing Conditions ====&lt;br /&gt;
For flight in icing conditions the following equipment must be installed inaccordance with Piper drawings or in an FAA approved manner:&lt;br /&gt;
* Pneumatic wing end empennage boots&lt;br /&gt;
* Electrothermal propeller boots&lt;br /&gt;
* Electric windshield panel&lt;br /&gt;
* Heated pitot head&lt;br /&gt;
* Wing ice light&lt;br /&gt;
* Heated lift detectors&lt;br /&gt;
* Propeller spinners must be installed&lt;br /&gt;
&lt;br /&gt;
==== Operating Altitude Limitations ====&lt;br /&gt;
Flight above 25,000 feet is not approved. Flight up to and including 25,000 feet is approved if equipped with oxygen in accordance with FAR 23.1441 and avionics in accordance with FAR 91 or FAR 135.&lt;br /&gt;
&lt;br /&gt;
== Development status/Issues/Todo ==&lt;br /&gt;
'''FDM (JSBSim):'''&lt;br /&gt;
* poor single engine performance &lt;br /&gt;
* fuel source not switchable or cutable&lt;br /&gt;
* flap operation should not emit a flap motor sound&lt;br /&gt;
* moving aircraft with parking brake set and full power&lt;br /&gt;
&lt;br /&gt;
'''Autopilot:'''&lt;br /&gt;
* The autopilot may be unstable in certain situations. A complete rework is in progress and will be commited to CVS ''&amp;quot;soon&amp;quot;'' --[[User:T3r|T3r]] 21:32, 28 February 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
'''Electrical system:'''&lt;br /&gt;
* Master switch no electrical function&lt;br /&gt;
* Generator L/H and R/H produce the same output when on&lt;br /&gt;
&lt;br /&gt;
'''Avionics:'''&lt;br /&gt;
* KI228 RMI shows wrong heading. If the ADF indicator is reconfigured from a KI227 to KI228 with a compass card rotation other than zero, the KI228 does not show the same heading as the HSI.&lt;br /&gt;
''REMARK:'' This is fixed in CVS version.&lt;br /&gt;
* No transponder. &lt;br /&gt;
''REMARK:'' There is a GTX330 transponder as an empty 3d model without functionality. &lt;br /&gt;
* No GPS. &lt;br /&gt;
''REMARK:'' There is a GPS155XL GPS as an empty 3d model without functionality.&lt;br /&gt;
&lt;br /&gt;
'''General:'''&lt;br /&gt;
* engine sound in cockpit does not differ from outside engine sound&lt;br /&gt;
* animations of structural icing on wings, stabilizer, fin, etc.missing&lt;br /&gt;
&lt;br /&gt;
{{Piper}}&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
== Related content ==&lt;br /&gt;
* [[Seneca II Checklist]]&lt;br /&gt;
* [[Seneca II HOWTO]]&lt;br /&gt;
* [[Seneca II Panel Reference]]&lt;br /&gt;
* [[HSI|HSI, Horizontal Situation Indicator]] &lt;br /&gt;
* [[Kx165|KX165 COM/NAV Radio]]&lt;br /&gt;
&lt;br /&gt;
=== Related lists ===&lt;br /&gt;
* [[Aircraft]]&lt;br /&gt;
* [[Aircraft Todo]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Aircraft]]&lt;br /&gt;
[[Category:Civilian aircraft]]&lt;br /&gt;
[[Category:Aircraft TODO]]&lt;br /&gt;
[[Category:Twin Engine Piston]]&lt;br /&gt;
[[Category:Piper PA34-200T Seneca II]]&lt;br /&gt;
[[Category:Model with well-implemented cockpit]]&lt;br /&gt;
[[Category:Candidate Aircraft for next release]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Piper PA34-200T Seneca II]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Weather&amp;diff=24972</id>
		<title>Weather</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Weather&amp;diff=24972"/>
		<updated>2010-10-30T20:40:44Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Explanation */ spelling&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:3D_clouds.jpg|thumb|270px|[[3D clouds]] in [[1.9.0-prerelease]] version as seen from a [[EC135]].]]&lt;br /&gt;
[[Image:weather_scenario.jpg|thumb|270px|The Weather Scenario window in FlightGear 1.9.1.]]&lt;br /&gt;
[[Image:New_Weather_Scenario.jpg|thumb|270px|The new Weather Scenario window in FlightGear CVS.]]&lt;br /&gt;
FlightGear has an impressive weather system, including real weather fetch, predefined weather scenarios, [[3D clouds]] and lightning.&lt;br /&gt;
&lt;br /&gt;
==How FlightGear creates weather==&lt;br /&gt;
Weather in reality is the state of the atmosphere at a given time for a given place. Calculating the complete atmosphere or even a small part of it will easily eat up all your computing power and result in very limited frame rates. FlightGear only calculates the state of the atmosphere for a vertical line beginning at earth's center straight through your aircraft up to approx. 100,000ft AGL. Most calculations are based on the [http://en.wikipedia.org/wiki/International_Standard_Atmosphere International Standard Atmosphere].&lt;br /&gt;
FlightGear's fundamental atmosphere parameters calculated are:&lt;br /&gt;
* temperature&lt;br /&gt;
* dew point&lt;br /&gt;
* pressure&lt;br /&gt;
* density&lt;br /&gt;
* wind (three dimensional)&lt;br /&gt;
* visibility&lt;br /&gt;
&lt;br /&gt;
===Atmosphere===&lt;br /&gt;
The line for which FlightGear calculates the atmosphere is divided into two major segments and several sub segments. The bottom major segment (the one closest to the ground) is called the boundary layer. It reaches up to 500ft above ground and connects directly above it to the so called aloft layer. By definition, in the boundary layer, the atmosphere - mainly the wind - is affected by the structure of the earth's surface, while in the aloft layer there is a free flow of air.&lt;br /&gt;
Within the boundary and the aloft layer, one up to many layers of atmosphere may be defined that have certain characteristics, like wind direction and speed.&lt;br /&gt;
The basic weather definition in FlightGear is&lt;br /&gt;
* Boundary layer, 0ft&lt;br /&gt;
** wind 270@3KT&lt;br /&gt;
** visibility 10SM&lt;br /&gt;
** pressure 29,92INHG / 1013hPa&lt;br /&gt;
** temperature 15, dewpoint 5&lt;br /&gt;
* Boundary layer, 500ft&lt;br /&gt;
** wind 280@6KT&lt;br /&gt;
* Aloft layer, 3000ft&lt;br /&gt;
** wind 300@10KT&lt;br /&gt;
* Aloft layer, 6000ft&lt;br /&gt;
** wind 310@20KT&lt;br /&gt;
* Aloft layer, 9000ft&lt;br /&gt;
** wind 320@30KT&lt;br /&gt;
All other values are derived from these parameters. When the aircraft changes altitude and passes through these layers, a linear interpolation between the parameters for the entry above and below your position is performed to compute the values for your exact altitude.&lt;br /&gt;
The atmospheric parameters described here are defined in preferences.xml and can be changed at runtime by selecting '''Environment-&amp;gt;Weather Conditions''' from the menu. The entry &amp;quot;Boundary transition depth&amp;quot; defines the thickness of the zone where the effects of the boundary layer and the aloft layer mix. When you fly within 500ft of the border between boundary and aloft layer, both tables are interpolated.&lt;br /&gt;
&lt;br /&gt;
===Clouds===&lt;br /&gt;
Clouds are - other than in real life - not visible humidity, when dew point and temperature match. They are a separate system and so are defined separately. They are also stacked in layers and for each layer the defining parameters for clouds are&lt;br /&gt;
* coverage (clear, few, scattered, broken, overcast)&lt;br /&gt;
* the elevation of cloud base (height above ground, not altitude!)&lt;br /&gt;
* the thickness (distance from cloud base to cloud top)&lt;br /&gt;
* the span (how far away do the clouds reach)&lt;br /&gt;
Once again, definition of the base cloud set is in preferences.xml and runtime adjustments can be done via the menu '''Environment-&amp;gt;Clouds'''&lt;br /&gt;
&lt;br /&gt;
==Defining Weather==&lt;br /&gt;
Defining weather can be a tedious task. Setting all the parameters for each layer and defining clouds is not everybody's fun. To get a weather definition done quickly, FlightGear has a build in METAR interpreter. This can read the coded weather information from a METAR and apply a more or less reasonable weather, that matches the conditions described in the METAR. Since a METAR only describes the weather a a station on the ground, many parameters, esp. for the higher atmosphere are just plain guesses which just try to be reasonable. &lt;br /&gt;
You can either pass a metar string as a command line option like&lt;br /&gt;
 --metar=&amp;quot;EDDH 280920Z 28020KT 9999 SCT030 14/07 Q1020 NOSIG&amp;quot;&lt;br /&gt;
or use the Weather Scenario dialog from the menu at '''Environment-&amp;gt;Weather Scenario''', where you can select a predefined weather, enter your own METAR or even enable live weather data. This options enables a task, that calculates your nearest airport and fetches the current METAR for that station from NOAA weather service. &lt;br /&gt;
An internal interpolation routine applies weather changes smoothly when changing the METAR.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==METAR==&lt;br /&gt;
A [[METAR]] is a codified observation message indicating an airfield weather conditions observed at a given time. There are different ways of messaging weather reports, but in [[FlightGear]] is [[METAR]] used.&lt;br /&gt;
&lt;br /&gt;
The [[METAR]]-message can be found acros the menu (Weather &amp;gt; Weather Scenario). To have the actual weather (or playing with [[ATC]]) you need to enable the Real weather fetch in the [[FlightGear Wizard]].&lt;br /&gt;
&lt;br /&gt;
Such a message is established every hour.&lt;br /&gt;
&lt;br /&gt;
===Explanation===&lt;br /&gt;
'''Example:''' &lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot;; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse:collapse; border:1px solid silver;&amp;quot; &lt;br /&gt;
|2008/03/15 12:24&lt;br /&gt;
|KSFO&lt;br /&gt;
|151224Z&lt;br /&gt;
|05012KT&lt;br /&gt;
|10SM&lt;br /&gt;
|SN&lt;br /&gt;
|BKN050&lt;br /&gt;
|02/M08&lt;br /&gt;
|A3016&lt;br /&gt;
|RMK AO2 SLP228&lt;br /&gt;
|T00221083&lt;br /&gt;
|- &lt;br /&gt;
|1&lt;br /&gt;
|2&lt;br /&gt;
|3&lt;br /&gt;
|4&lt;br /&gt;
|5&lt;br /&gt;
|6&lt;br /&gt;
|7&lt;br /&gt;
|8&lt;br /&gt;
|9&lt;br /&gt;
|10&lt;br /&gt;
|11&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
# Date&lt;br /&gt;
# [[ICAO]] Identifier (4-letter)&lt;br /&gt;
# Issuance Time DDHHMMz (UTC) &lt;br /&gt;
#*COR (CCD in Canada) if correction to observation&lt;br /&gt;
#Wind&lt;br /&gt;
#*First 3 digits: True Wind direction or average if variable (VRB).&lt;br /&gt;
#**Note: If the wind direction varies 60° or more, the direction will be indicated with a V (e.g. 180V250)&lt;br /&gt;
#*Next 2 digits: Mean speed and units&lt;br /&gt;
#** KT=knots, KMH=kilometers/hour, MPS=meters/second&lt;br /&gt;
#*G (gust) as needed – 2 or 3 digit maximum speed&lt;br /&gt;
#*Calm will be indicated by 00000KT&lt;br /&gt;
#*Example: 18012G22KT 150V240&lt;br /&gt;
#Horizontal Visibility&lt;br /&gt;
#*Prevailing Visibility (PV)&lt;br /&gt;
#**Statue miles (SM) and fractions (US &amp;amp; Canada only) or,&lt;br /&gt;
#**4 digit minimum visibility in meters, and, &lt;br /&gt;
#**Lowest value and direction, as required (shown as a remark)&lt;br /&gt;
#*Runway Visual Range (RVR)&lt;br /&gt;
#**R: Runway Designator, L/R/C as needed, “/”&lt;br /&gt;
#**P/M: Plus/Minus (US only)&lt;br /&gt;
#**4 digit value (feet/meters)&lt;br /&gt;
#**V (variability) with tendency U/D/N (up/down/no change)&lt;br /&gt;
#**Example: R18R/1200FTV/U&lt;br /&gt;
#Present Weather (Constructed sequentially):&lt;br /&gt;
#*Intensity&lt;br /&gt;
#*Descriptor&lt;br /&gt;
#*Precipitation (Dominant type is listed first if more than one type reported)&lt;br /&gt;
#*Obscuration&lt;br /&gt;
#*Other&lt;br /&gt;
#Sky Cover&lt;br /&gt;
#*Cloud Description&lt;br /&gt;
#**Amount in eights (octas)&lt;br /&gt;
#**SKC=Sky Clear (clear below 12,000 for ASOS/AWOS)&lt;br /&gt;
#**NSC=No significant clouds&lt;br /&gt;
#**FEW=Few (1/8 to 2/8 sky cover)&lt;br /&gt;
#**SCT=Scattered (3/8 to 4/8 sky cover)&lt;br /&gt;
#**BKN=Broken (5/8 to 7/8 sky cover)&lt;br /&gt;
#**OVC=Overcast (8/8 sky cover)&lt;br /&gt;
#Temperature/Dewpoint (whole °C) (preceded by M=minus)&lt;br /&gt;
#*First 2 digits = temperature&lt;br /&gt;
#*Second 2 digits = dewpoint&lt;br /&gt;
#Altimeter setting (QNH) and indicator (A=InHg, Q=hPa)&lt;br /&gt;
#Supplementary Information&lt;br /&gt;
#*RE = Recent weather followed by weather codes&lt;br /&gt;
#*WS = Windshear, followed by:&lt;br /&gt;
#**TKOF/LDG (takeoff/landing)&lt;br /&gt;
#**RWY (2 digits runway identifier and designator L/R/C)&lt;br /&gt;
#*RMK = Remark&lt;br /&gt;
#**SLP = Sea Level Pressure&lt;br /&gt;
#**T00221083 (Expanded temp/dewpoint) &lt;br /&gt;
#**1st, 5th digits: 0=plus, 1=minus&lt;br /&gt;
#**2nd-4th digits: temp (decimal missing) (02.2)&lt;br /&gt;
#**6th-8th digits: dewpoint (decimal missing) (-8.3)&lt;br /&gt;
#Trend Forecast (2 hours from time of observation) (Not used in US)&lt;br /&gt;
#*PROB and 2 digits (30 or 40) = probability 30% or 40%&lt;br /&gt;
#*Used to indicate the probability of occurance of alternate element(s) or temporary fluctuations&lt;br /&gt;
#*Change Indicator&lt;br /&gt;
#**BECMG = Becoming (used where changes are expected to reach or pass through specified values&lt;br /&gt;
#**TEMPO = Temporary (fluctuations of less than one hour duration&lt;br /&gt;
#**NOSIG = No significant change&lt;br /&gt;
#*Forecast Wind (same as item 4)&lt;br /&gt;
#*Forecast Visibility (as item 5) (9999 indicates 10Kilometers vis or greater)&lt;br /&gt;
#*Forecast Weather (as item 6)&lt;br /&gt;
#*Forecast Cloud (as item 7)&lt;br /&gt;
&lt;br /&gt;
== TAF ==&lt;br /&gt;
In meteorology and aviation, TAF is a format for reporting weather forecast information, particularly as it relates to aviation. &amp;quot;TAF&amp;quot; is an acronym of Terminal Aerodrome Forecast or, in some countries, Terminal Area Forecast. Generally, TAF's can apply to a 9- or 12-hour forecast; some TAFs cover an 18- or 24-hour period; and as of November 5,2008, TAFs for some major airports cover 30 hours periods. The date/time group reflects the new 30 hour period in Coordinated Universal Time (UTC), as always.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Explanation===&lt;br /&gt;
This TAF example of a 30-hour TAF, released on November 5 2008 at 1730 UTC:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;TAF KXYZ 051730Z 0518/0624 31008KT &lt;br /&gt;
     3SM -SHRA BKN020&lt;br /&gt;
     FM052300 30006KT 5SM -SHRA OVC030 &lt;br /&gt;
     PROB30 0604/0606 VRB20G35KT 1SM &lt;br /&gt;
     TSRA BKN015CB &lt;br /&gt;
     FM 060600 250010KT 4SM -SHRA OVC050&lt;br /&gt;
     TEMPO 0608/0611 2SM -SHRA OVC030=  &lt;br /&gt;
     RMK NXT FCST BY 00Z=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line contains identification and validity times.&lt;br /&gt;
*'''TAF''' indicates that the following is a terminal area forecast.&lt;br /&gt;
*'''KXYZ''' indicates the airport to which the forecast applies (ICAO airport code).&lt;br /&gt;
*'''051730Z''' indicates that the report was issued at 1730 UTC on the 5th of the month.&lt;br /&gt;
*'''0518/0624''' indicates that the report is valid from 1800 UTC on the 5th until 2400 UTC on the following day.&lt;br /&gt;
&lt;br /&gt;
The remainder of the first line and the second line contain the initial forecast conditions.  Variations of the codes used for various weather conditions are many.&lt;br /&gt;
*'''31008KT''' indicates that the wind will be from 310 degrees at 8 knots.&lt;br /&gt;
*'''3SM -SHRA BKN020''' indicates that visibility will be 3SM (statute miles) in light (-) showers (SH) of rain (RA), with a broken ceiling (at least 5/8 of the sky covered) at 2,000 feet.&lt;br /&gt;
&lt;br /&gt;
Each line beginning with '''FM''' starts a new forecast period.&lt;br /&gt;
*'''FM052300''' indicates the next period lasts from (FM) 2300 UTC on the 5th to 0000 UTC on the 6th.&lt;br /&gt;
The remainder of the line has similar formatting to the other forecast lines.&lt;br /&gt;
&lt;br /&gt;
The final line is for errata, comments, and remarks.&lt;br /&gt;
*'''RMK NXT FCST BY 00Z''' indicates a remark that the next forecast will be issued by 0000 UTC.&lt;br /&gt;
&lt;br /&gt;
===External Links===&lt;br /&gt;
* [http://aviationweather.gov/static/help/taf-decode.php Decoding a TAF]&lt;br /&gt;
&lt;br /&gt;
==Related content==&lt;br /&gt;
* [[Howto: Fetch live aloft data]]&lt;br /&gt;
&lt;br /&gt;
[[Category:FlightGear feature]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Building_FlightGear_-_Debian&amp;diff=22930</id>
		<title>Building FlightGear - Debian</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Building_FlightGear_-_Debian&amp;diff=22930"/>
		<updated>2010-07-21T08:17:58Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Build and install */ improve phrasing&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HowTo build on Debian =&lt;br /&gt;
&lt;br /&gt;
HowTo build FlightGear 2.0.0 or CVS on GNU/Linux Debian '''Stable''' 5.x (Lenny).&lt;br /&gt;
&lt;br /&gt;
This HowTo may also work with '''Testing'''/'''Unstable''' except that some things are easier because of more up to date packages. So, before fetching something check the version of the available -dev package for it.&lt;br /&gt;
&lt;br /&gt;
It even *should* work with '''Etch''', but I am not certain about some dependencies. [http://wiki.flightgear.org/index.php?title=Talk:Building_Flightgear_-_Debian&amp;amp;action=edit Reports] are welcome.&lt;br /&gt;
&lt;br /&gt;
If you don't want to make your hands dirty, have a look at [[Scripted_Compilation_on_Linux_Debian/Ubuntu]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Requirements and Preparations ==&lt;br /&gt;
You need an OpenGL capable graphics including a proper installed driver.&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also a bunch of packages (and some of their dependencies) are required:&lt;br /&gt;
*gcc, g++, make, automake1.9, pkg-config&lt;br /&gt;
*mawk (or gawk)&lt;br /&gt;
*cmake   (min. version 2.6.0-5,  for Etch available on backports.org!)&lt;br /&gt;
*cvs, subversion, wget&lt;br /&gt;
&amp;lt;!--*libsvn-dev, for [[Terrasync]]s proper operation.--&amp;gt;&lt;br /&gt;
*freeglut3-dev, libgl1-mesa-dev, libxrandr-dev&lt;br /&gt;
*libxi-dev, libxmu-dev, libxext-dev&lt;br /&gt;
*libopenal-dev (see [[#libopenal|libopenal]]), libalut-dev&lt;br /&gt;
*libjpeg62-dev, libtiff4-dev, libpng12-dev&lt;br /&gt;
*libboost1.37-dev  (Not available for Lenny atm, see [[#Boost Library|Boost Library]] below.)&lt;br /&gt;
&lt;br /&gt;
During installation packages ''simgear-dev'' and ''openscenegraph-dev'' *must not* be installed. They can safely be re-installed after compilation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Build and install ==&lt;br /&gt;
Because we are going to install versions different to the ones in the repositries it is recommended to install FG-2.0.0 and/or CVS in a place independent to the base system such as /usr/local/FG-2.0.0, /opt/FG-2.0.0 or in a subdirectory of your $HOME. I suggest to make it writeable by the user that there is no need to become root for the &amp;lt;code&amp;gt;make install&amp;lt;/code&amp;gt; commands. I'll use &amp;lt;code&amp;gt;$prefix&amp;lt;/code&amp;gt; as a placeholder for this directory. &amp;lt;BR&amp;gt;&lt;br /&gt;
Another one will be &amp;lt;code&amp;gt;$srcdir&amp;lt;/code&amp;gt;, it stands for the absolute path to the directory which contains the folders of the various source codes. So in the following instructions you have to replace these with the local paths or even &amp;lt;code&amp;gt;export&amp;lt;/code&amp;gt; them during the process.&lt;br /&gt;
&lt;br /&gt;
Follow the instructions to fetch the sources and the data needed by FlightGear and the commands to build/install each source.&lt;br /&gt;
&lt;br /&gt;
Have in mind that the data is relatively large (CVS about 2 GB and 2.0.0 300 MB) so, to save some time, it is a good idea to fetch it while building the sources.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== libopenal ===&lt;br /&gt;
The libopenal-dev package in Lenny/Etch is too old for [[fgcom]]. For FlightGear it does work but not all features (like Doppler) are available, so installing an up to date version is recommended anyway.&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 wget http://kcat.strangesoft.net/openal-releases/openal-soft-1.11.753.tar.bz2&lt;br /&gt;
 tar xjf openal-soft-1.11.753.tar.bz2&lt;br /&gt;
 cd openal-soft-1.11.753/build&lt;br /&gt;
 cmake  -D CMAKE_INSTALL_PREFIX:PATH=&amp;quot;$prefix&amp;quot; ..&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== plib ===&lt;br /&gt;
Latest SVN is [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg20793.html recommended], yet package plib1.8.5-dev for Testing/Unstable does work as well.&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co https://plib.svn.sourceforge.net/svnroot/plib/trunk plib&lt;br /&gt;
 cd plib&lt;br /&gt;
 sed s/PLIB_TINY_VERSION\ \ 5/PLIB_TINY_VERSION\ \ 6/ -i src/util/ul.h&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
 ./configure --prefix=$prefix&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Boost Library ===&lt;br /&gt;
Version 1.37 is needed. At least for Lenny/Etch this means getting the sources because this is not available atm on backports.org. Testing/Unstable users may have more luck and a package is available, libboost-1.37-dev or newer.&lt;br /&gt;
&lt;br /&gt;
To build SimGear, FlightGear, fgrun and fgcom some boostlib header files are required, no need to compile and install it. If you have installed a libboost1.37-dev (or higher) package on your system you don't have to bother at all with it. If not, you have to tell each ./configure where the header files are. To do so, add the option &amp;lt;code&amp;gt;CPPFLAGS=-I$prefix/include&amp;lt;/code&amp;gt; to the SimGear, FlightGear and fgrun &amp;lt;code&amp;gt;./configure&amp;lt;/code&amp;gt; commands. We copy the header files to $prefix/include because fgcom will need them there.&lt;br /&gt;
&lt;br /&gt;
Get the newest version tar ball from http://sourceforge.net/projects/boost/files/boost/, extract it into &amp;lt;code&amp;gt;$srcdir&amp;lt;/code&amp;gt; then:&lt;br /&gt;
 cp -R $srcdir/boost-[version]/boost/ $prefix/include/&lt;br /&gt;
&lt;br /&gt;
=== OpenSceneGraph ===&lt;br /&gt;
For FlightGear 2.0.0 one may use the latest (or at least 2.9.6) developer release from http://www.openscenegraph.org/projects/osg/wiki/Downloads/DeveloperReleases and extract it into &amp;lt;code&amp;gt;$srcdir&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Mostly this is ok for FlightGear CVS as well as it is stable. However, sometimes the release is not fresh enough and one have to get the latest developments via SVN:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co http://www.openscenegraph.org/svn/osg/OpenSceneGraph/trunk OpenSceneGraph&lt;br /&gt;
&lt;br /&gt;
cmake demands a build directory separate to its source directory. So &amp;lt;code&amp;gt;mkdir&amp;lt;/code&amp;gt; one and &amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; into it.&lt;br /&gt;
 cmake -D CMAKE_BUILD_TYPE=&amp;quot;Release&amp;quot; -D CMAKE_CXX_FLAGS=&amp;quot;-O3&amp;quot; -D CMAKE_C_FLAGS=&amp;quot;-O3&amp;quot; \&lt;br /&gt;
    -D CMAKE_INSTALL_PREFIX:PATH=&amp;quot;$prefix&amp;quot; $srcdir/OpenSceneGraph[-version]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== SimGear ===&lt;br /&gt;
2.0.0:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 wget http://mirrors.ibiblio.org/pub/mirrors/simgear/ftp/Source/SimGear-2.0.0.tar.gz&lt;br /&gt;
 tar xzf SimGear-2.0.0.tar.gz&lt;br /&gt;
 cd SimGear-2.0.0&lt;br /&gt;
&lt;br /&gt;
CVS:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 git clone git://gitorious.org/fg/simgear.git simgear&lt;br /&gt;
 cd simgear&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
&lt;br /&gt;
2.0.0 and CVS:&lt;br /&gt;
 ./configure --prefix=$prefix [CPPFLAGS=-I$prefix/include LDFLAGS=&amp;quot;-L$prefix/lib -L$prefix/lib64&amp;quot;]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== FlightGear source ===&lt;br /&gt;
2.0.0:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 wget http://mirrors.ibiblio.org/pub/mirrors/flightgear/ftp/Source/FlightGear-2.0.0.tar.gz&lt;br /&gt;
 tar xzf FlightGear-2.0.0.tar.gz&lt;br /&gt;
 cd FlightGear-2.0.0&lt;br /&gt;
&lt;br /&gt;
CVS:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 git clone git://gitorious.org/fg/flightgear.git flightgear&lt;br /&gt;
 cd flightgear&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
&lt;br /&gt;
2.0.0 and CVS:&lt;br /&gt;
 ./configure --prefix=$prefix [CPPFLAGS=-I$prefix/include/ LDFLAGS=&amp;quot;-L$prefix/lib -L$prefix/lib64&amp;quot;]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== FlightGear data ===&lt;br /&gt;
2.0.0:&lt;br /&gt;
 cd $prefix&lt;br /&gt;
 wget http://mirrors.ibiblio.org/pub/mirrors/flightgear/ftp/Shared/FlightGear-data-2.0.0.tar.bz2&lt;br /&gt;
 tar xjf FlightGear-data-2.0.0.tar.bz2&lt;br /&gt;
&lt;br /&gt;
GIT:&lt;br /&gt;
 cd $prefix&lt;br /&gt;
 git clone git://gitorious.org/fg/fgdata.git data&lt;br /&gt;
&lt;br /&gt;
Or to Fetch A bundle that can be Downloaded in parts :&lt;br /&gt;
 cd $prefix&lt;br /&gt;
 wget http://peter-server.homelinux.net/fgdata/fgdata/fgdata.bundle&lt;br /&gt;
&lt;br /&gt;
=== Trial run ===&lt;br /&gt;
When all the builds are done and the data download has finished it is time for a test run:&lt;br /&gt;
 export LD_LIBRARY_PATH=$prefix/lib/:$LD_LIBRARY_PATH&lt;br /&gt;
 $prefix/bin/fgfs --fg-root=$prefix/data&lt;br /&gt;
&lt;br /&gt;
For the future, if you want to start FlightGear from command line have a look at [[fgfsrc]], if you prefer a graphical user interface continue with [[#fgrun|compiling fgrun]]. Have in mind that fgfs need to find our self compiled libraries and therefore we have to tell the linker (ld) where to find them. That is what the first line here does.&lt;br /&gt;
&lt;br /&gt;
== Optional Software ==&lt;br /&gt;
&lt;br /&gt;
=== fgrun ===&lt;br /&gt;
To build [[fgrun]] two more package is required:&lt;br /&gt;
*libfltk1.1-dev fluid&lt;br /&gt;
&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co http://fgrun.svn.sourceforge.net/svnroot/fgrun/trunk fgrun&lt;br /&gt;
 cd fgrun&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
 ./configure --prefix=$prefix  [CPPFLAGS=-I$prefix/include/]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== fgcom ===&lt;br /&gt;
For [[fgcom]] unfortunately there is one more dependency which cannot be solved with packages on Lenny/Etch, see [[#libopenal|libopenal]].&lt;br /&gt;
&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co https://appfgcom.svn.sourceforge.net/svnroot/fgcom/trunk fgcom&lt;br /&gt;
 cd fgcom/src&lt;br /&gt;
 make INSTALL_BIN=$prefix/bin INSTALL_DIR=$prefix/fgcom \&lt;br /&gt;
    PLIB_PREFIX=$prefix OPENAL_PREFIX=$prefix install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--== Keeping the CVS version up to date ==&lt;br /&gt;
&lt;br /&gt;
...to be continued. ;-)&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Building}}&lt;br /&gt;
&lt;br /&gt;
[[de:FlightGear_bauen_-_Debian]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Building_FlightGear_-_Debian&amp;diff=22929</id>
		<title>Building FlightGear - Debian</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Building_FlightGear_-_Debian&amp;diff=22929"/>
		<updated>2010-07-21T08:13:58Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Build and install */ improve phrasing&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HowTo build on Debian =&lt;br /&gt;
&lt;br /&gt;
HowTo build FlightGear 2.0.0 or CVS on GNU/Linux Debian '''Stable''' 5.x (Lenny).&lt;br /&gt;
&lt;br /&gt;
This HowTo may also work with '''Testing'''/'''Unstable''' except that some things are easier because of more up to date packages. So, before fetching something check the version of the available -dev package for it.&lt;br /&gt;
&lt;br /&gt;
It even *should* work with '''Etch''', but I am not certain about some dependencies. [http://wiki.flightgear.org/index.php?title=Talk:Building_Flightgear_-_Debian&amp;amp;action=edit Reports] are welcome.&lt;br /&gt;
&lt;br /&gt;
If you don't want to make your hands dirty, have a look at [[Scripted_Compilation_on_Linux_Debian/Ubuntu]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Requirements and Preparations ==&lt;br /&gt;
You need an OpenGL capable graphics including a proper installed driver.&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also a bunch of packages (and some of their dependencies) are required:&lt;br /&gt;
*gcc, g++, make, automake1.9, pkg-config&lt;br /&gt;
*mawk (or gawk)&lt;br /&gt;
*cmake   (min. version 2.6.0-5,  for Etch available on backports.org!)&lt;br /&gt;
*cvs, subversion, wget&lt;br /&gt;
&amp;lt;!--*libsvn-dev, for [[Terrasync]]s proper operation.--&amp;gt;&lt;br /&gt;
*freeglut3-dev, libgl1-mesa-dev, libxrandr-dev&lt;br /&gt;
*libxi-dev, libxmu-dev, libxext-dev&lt;br /&gt;
*libopenal-dev (see [[#libopenal|libopenal]]), libalut-dev&lt;br /&gt;
*libjpeg62-dev, libtiff4-dev, libpng12-dev&lt;br /&gt;
*libboost1.37-dev  (Not available for Lenny atm, see [[#Boost Library|Boost Library]] below.)&lt;br /&gt;
&lt;br /&gt;
During installation packages ''simgear-dev'' and ''openscenegraph-dev'' *must not* be installed. They can safely be re-installed after compilation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Build and install ==&lt;br /&gt;
Because we are going to install versions different to the ones in the repositries it is recommended to install FG-2.0.0 and/or CVS in a place independent to the base system such as /usr/local/FG-2.0.0, /opt/FG-2.0.0 or in a subdirectory of your $HOME. I suggest to make it writeable by the user that there is no need to become root for the &amp;lt;code&amp;gt;make install&amp;lt;/code&amp;gt; commands. I'll use &amp;lt;code&amp;gt;$prefix&amp;lt;/code&amp;gt; as a placeholder for this directory. &amp;lt;BR&amp;gt;&lt;br /&gt;
Another one will be &amp;lt;code&amp;gt;$srcdir&amp;lt;/code&amp;gt;, it stands for the absolute path to the directory which contains the folders of the various source codes. So in the following instructions you have to replace these with the local paths or even &amp;lt;code&amp;gt;export&amp;lt;/code&amp;gt; them during the process.&lt;br /&gt;
&lt;br /&gt;
Subsequent the instructions to fetch the sources and the data needed by FlightGear and the commands to build/install each source.&lt;br /&gt;
&lt;br /&gt;
Have in mind that the data is relatively huge (CVS about 2 GB and 2.0.0 300 MB) so, to save some time, it is a good idea to fetch it while building the sources.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== libopenal ===&lt;br /&gt;
The libopenal-dev package in Lenny/Etch is too old for [[fgcom]]. For FlightGear it does work but not all features (like Doppler) are available, so installing an up to date version is recommended anyway.&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 wget http://kcat.strangesoft.net/openal-releases/openal-soft-1.11.753.tar.bz2&lt;br /&gt;
 tar xjf openal-soft-1.11.753.tar.bz2&lt;br /&gt;
 cd openal-soft-1.11.753/build&lt;br /&gt;
 cmake  -D CMAKE_INSTALL_PREFIX:PATH=&amp;quot;$prefix&amp;quot; ..&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== plib ===&lt;br /&gt;
Latest SVN is [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg20793.html recommended], yet package plib1.8.5-dev for Testing/Unstable does work as well.&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co https://plib.svn.sourceforge.net/svnroot/plib/trunk plib&lt;br /&gt;
 cd plib&lt;br /&gt;
 sed s/PLIB_TINY_VERSION\ \ 5/PLIB_TINY_VERSION\ \ 6/ -i src/util/ul.h&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
 ./configure --prefix=$prefix&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Boost Library ===&lt;br /&gt;
Version 1.37 is needed. At least for Lenny/Etch this means getting the sources because this is not available atm on backports.org. Testing/Unstable users may have more luck and a package is available, libboost-1.37-dev or newer.&lt;br /&gt;
&lt;br /&gt;
To build SimGear, FlightGear, fgrun and fgcom some boostlib header files are required, no need to compile and install it. If you have installed a libboost1.37-dev (or higher) package on your system you don't have to bother at all with it. If not, you have to tell each ./configure where the header files are. To do so, add the option &amp;lt;code&amp;gt;CPPFLAGS=-I$prefix/include&amp;lt;/code&amp;gt; to the SimGear, FlightGear and fgrun &amp;lt;code&amp;gt;./configure&amp;lt;/code&amp;gt; commands. We copy the header files to $prefix/include because fgcom will need them there.&lt;br /&gt;
&lt;br /&gt;
Get the newest version tar ball from http://sourceforge.net/projects/boost/files/boost/, extract it into &amp;lt;code&amp;gt;$srcdir&amp;lt;/code&amp;gt; then:&lt;br /&gt;
 cp -R $srcdir/boost-[version]/boost/ $prefix/include/&lt;br /&gt;
&lt;br /&gt;
=== OpenSceneGraph ===&lt;br /&gt;
For FlightGear 2.0.0 one may use the latest (or at least 2.9.6) developer release from http://www.openscenegraph.org/projects/osg/wiki/Downloads/DeveloperReleases and extract it into &amp;lt;code&amp;gt;$srcdir&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Mostly this is ok for FlightGear CVS as well as it is stable. However, sometimes the release is not fresh enough and one have to get the latest developments via SVN:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co http://www.openscenegraph.org/svn/osg/OpenSceneGraph/trunk OpenSceneGraph&lt;br /&gt;
&lt;br /&gt;
cmake demands a build directory separate to its source directory. So &amp;lt;code&amp;gt;mkdir&amp;lt;/code&amp;gt; one and &amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; into it.&lt;br /&gt;
 cmake -D CMAKE_BUILD_TYPE=&amp;quot;Release&amp;quot; -D CMAKE_CXX_FLAGS=&amp;quot;-O3&amp;quot; -D CMAKE_C_FLAGS=&amp;quot;-O3&amp;quot; \&lt;br /&gt;
    -D CMAKE_INSTALL_PREFIX:PATH=&amp;quot;$prefix&amp;quot; $srcdir/OpenSceneGraph[-version]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== SimGear ===&lt;br /&gt;
2.0.0:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 wget http://mirrors.ibiblio.org/pub/mirrors/simgear/ftp/Source/SimGear-2.0.0.tar.gz&lt;br /&gt;
 tar xzf SimGear-2.0.0.tar.gz&lt;br /&gt;
 cd SimGear-2.0.0&lt;br /&gt;
&lt;br /&gt;
CVS:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 git clone git://gitorious.org/fg/simgear.git simgear&lt;br /&gt;
 cd simgear&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
&lt;br /&gt;
2.0.0 and CVS:&lt;br /&gt;
 ./configure --prefix=$prefix [CPPFLAGS=-I$prefix/include LDFLAGS=&amp;quot;-L$prefix/lib -L$prefix/lib64&amp;quot;]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== FlightGear source ===&lt;br /&gt;
2.0.0:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 wget http://mirrors.ibiblio.org/pub/mirrors/flightgear/ftp/Source/FlightGear-2.0.0.tar.gz&lt;br /&gt;
 tar xzf FlightGear-2.0.0.tar.gz&lt;br /&gt;
 cd FlightGear-2.0.0&lt;br /&gt;
&lt;br /&gt;
CVS:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 git clone git://gitorious.org/fg/flightgear.git flightgear&lt;br /&gt;
 cd flightgear&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
&lt;br /&gt;
2.0.0 and CVS:&lt;br /&gt;
 ./configure --prefix=$prefix [CPPFLAGS=-I$prefix/include/ LDFLAGS=&amp;quot;-L$prefix/lib -L$prefix/lib64&amp;quot;]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== FlightGear data ===&lt;br /&gt;
2.0.0:&lt;br /&gt;
 cd $prefix&lt;br /&gt;
 wget http://mirrors.ibiblio.org/pub/mirrors/flightgear/ftp/Shared/FlightGear-data-2.0.0.tar.bz2&lt;br /&gt;
 tar xjf FlightGear-data-2.0.0.tar.bz2&lt;br /&gt;
&lt;br /&gt;
GIT:&lt;br /&gt;
 cd $prefix&lt;br /&gt;
 git clone git://gitorious.org/fg/fgdata.git data&lt;br /&gt;
&lt;br /&gt;
Or to Fetch A bundle that can be Downloaded in parts :&lt;br /&gt;
 cd $prefix&lt;br /&gt;
 wget http://peter-server.homelinux.net/fgdata/fgdata/fgdata.bundle&lt;br /&gt;
&lt;br /&gt;
=== Trial run ===&lt;br /&gt;
When all the builds are done and the data download has finished it is time for a test run:&lt;br /&gt;
 export LD_LIBRARY_PATH=$prefix/lib/:$LD_LIBRARY_PATH&lt;br /&gt;
 $prefix/bin/fgfs --fg-root=$prefix/data&lt;br /&gt;
&lt;br /&gt;
For the future, if you want to start FlightGear from command line have a look at [[fgfsrc]], if you prefer a graphical user interface continue with [[#fgrun|compiling fgrun]]. Have in mind that fgfs need to find our self compiled libraries and therefore we have to tell the linker (ld) where to find them. That is what the first line here does.&lt;br /&gt;
&lt;br /&gt;
== Optional Software ==&lt;br /&gt;
&lt;br /&gt;
=== fgrun ===&lt;br /&gt;
To build [[fgrun]] two more package is required:&lt;br /&gt;
*libfltk1.1-dev fluid&lt;br /&gt;
&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co http://fgrun.svn.sourceforge.net/svnroot/fgrun/trunk fgrun&lt;br /&gt;
 cd fgrun&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
 ./configure --prefix=$prefix  [CPPFLAGS=-I$prefix/include/]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== fgcom ===&lt;br /&gt;
For [[fgcom]] unfortunately there is one more dependency which cannot be solved with packages on Lenny/Etch, see [[#libopenal|libopenal]].&lt;br /&gt;
&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co https://appfgcom.svn.sourceforge.net/svnroot/fgcom/trunk fgcom&lt;br /&gt;
 cd fgcom/src&lt;br /&gt;
 make INSTALL_BIN=$prefix/bin INSTALL_DIR=$prefix/fgcom \&lt;br /&gt;
    PLIB_PREFIX=$prefix OPENAL_PREFIX=$prefix install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--== Keeping the CVS version up to date ==&lt;br /&gt;
&lt;br /&gt;
...to be continued. ;-)&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Building}}&lt;br /&gt;
&lt;br /&gt;
[[de:FlightGear_bauen_-_Debian]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Howto:Make_a_clickable_panel&amp;diff=22015</id>
		<title>Howto:Make a clickable panel</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Howto:Make_a_clickable_panel&amp;diff=22015"/>
		<updated>2010-06-06T05:59:54Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Pick */ improve sentence structure&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There are two methodes to '''make a clickable planel''' in [[FlightGear]] at the moment:&lt;br /&gt;
* '''Hotspot:''' adds a clickable (invisible) face at a certain position.&lt;br /&gt;
* '''Pick:''' makes a whole object clickable.&lt;br /&gt;
&lt;br /&gt;
The easiest to use is pick, since you do not have to look up all the coordinates. Also the pick animation is more realistic and therefore more often used.&lt;br /&gt;
&lt;br /&gt;
==Hotspot==&lt;br /&gt;
The hotspot animation is somewhat complicated. You have to define the x and y coordinates of every clickable &amp;quot;face&amp;quot; (hotspot) aswell the width and heigth of the hotspot to click on. See the following example of the [[Boeing 777-200|777-200]].&lt;br /&gt;
&lt;br /&gt;
===Panel file===&lt;br /&gt;
&lt;br /&gt;
Make a new panel file (.xml) in your aircrafts directory. The following lines are only placed on top of the file:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;PropertyList&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;name&amp;gt;777-200 Overhead Panel&amp;lt;/name&amp;gt;&lt;br /&gt;
 &amp;lt;background&amp;gt;Aircraft/777-200/Panels/transparent-bg.rgb&amp;lt;/background&amp;gt;&lt;br /&gt;
 &amp;lt;w&amp;gt;256&amp;lt;/w&amp;gt;&lt;br /&gt;
 &amp;lt;h&amp;gt;512&amp;lt;/h&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;instruments&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;instrument&amp;gt;&lt;br /&gt;
  &amp;lt;name&amp;gt;panel hotspots&amp;lt;/name&amp;gt;&lt;br /&gt;
  &amp;lt;x&amp;gt;128&amp;lt;/x&amp;gt;&lt;br /&gt;
  &amp;lt;y&amp;gt;256&amp;lt;/y&amp;gt;&lt;br /&gt;
  &amp;lt;w&amp;gt;256&amp;lt;/w&amp;gt;&lt;br /&gt;
  &amp;lt;h&amp;gt;512&amp;lt;/h&amp;gt;&lt;br /&gt;
  &amp;lt;w-base&amp;gt;256&amp;lt;/w-base&amp;gt;&lt;br /&gt;
  &amp;lt;h-base&amp;gt;512&amp;lt;/h-base&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;actions&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Now all hotspots need to be listed as seperate actions:&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;action&amp;gt;&lt;br /&gt;
  &amp;lt;name&amp;gt;Master Battery Switch&amp;lt;/name&amp;gt;&lt;br /&gt;
  &amp;lt;button&amp;gt;0&amp;lt;/button&amp;gt;&lt;br /&gt;
  &amp;lt;x&amp;gt;-278&amp;lt;/x&amp;gt;&lt;br /&gt;
  &amp;lt;y&amp;gt;-188&amp;lt;/y&amp;gt;&lt;br /&gt;
  &amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&lt;br /&gt;
  &amp;lt;h&amp;gt;10&amp;lt;/h&amp;gt;&lt;br /&gt;
  &amp;lt;binding&amp;gt;&lt;br /&gt;
   &amp;lt;command&amp;gt;property-toggle&amp;lt;/command&amp;gt;&lt;br /&gt;
   &amp;lt;property&amp;gt;/controls/electric/battery-switch&amp;lt;/property&amp;gt;&lt;br /&gt;
   &amp;lt;step&amp;gt;1&amp;lt;/step&amp;gt;&lt;br /&gt;
   &amp;lt;min&amp;gt;0&amp;lt;/min&amp;gt;&lt;br /&gt;
   &amp;lt;max&amp;gt;1&amp;lt;/max&amp;gt;&lt;br /&gt;
   &amp;lt;wrap&amp;gt;true&amp;lt;/wrap&amp;gt;&lt;br /&gt;
  &amp;lt;/binding&amp;gt;&lt;br /&gt;
 &amp;lt;/action&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We end the file with:&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;/actions&amp;gt;&lt;br /&gt;
 &amp;lt;/instrument&amp;gt;&lt;br /&gt;
 &amp;lt;/instruments&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;/PropertyList&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Model file===&lt;br /&gt;
Now we need to link to this file from our model's file. Add something similar to the following in your model file:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;panel&amp;gt;&lt;br /&gt;
  &amp;lt;path&amp;gt;Aircraft/777-200/Panels/oh-panel.xml&amp;lt;/path&amp;gt;&lt;br /&gt;
  &amp;lt;bottom-left&amp;gt;&lt;br /&gt;
   &amp;lt;x-m&amp;gt;-23.396&amp;lt;/x-m&amp;gt;&lt;br /&gt;
   &amp;lt;y-m&amp;gt;-0.522&amp;lt;/y-m&amp;gt;&lt;br /&gt;
   &amp;lt;z-m&amp;gt;0.992&amp;lt;/z-m&amp;gt;&lt;br /&gt;
  &amp;lt;/bottom-left&amp;gt;&lt;br /&gt;
  &amp;lt;bottom-right&amp;gt;&lt;br /&gt;
   &amp;lt;x-m&amp;gt;-23.396&amp;lt;/x-m&amp;gt;&lt;br /&gt;
   &amp;lt;y-m&amp;gt;0.522&amp;lt;/y-m&amp;gt;&lt;br /&gt;
   &amp;lt;z-m&amp;gt;0.992&amp;lt;/z-m&amp;gt;&lt;br /&gt;
   &amp;lt;/bottom-right&amp;gt;&lt;br /&gt;
   &amp;lt;top-left&amp;gt;&lt;br /&gt;
   &amp;lt;x-m&amp;gt;-22.686&amp;lt;/x-m&amp;gt;&lt;br /&gt;
   &amp;lt;y-m&amp;gt;-0.522&amp;lt;/y-m&amp;gt;&lt;br /&gt;
   &amp;lt;z-m&amp;gt;1.323&amp;lt;/z-m&amp;gt;&lt;br /&gt;
  &amp;lt;/top-left&amp;gt;&lt;br /&gt;
 &amp;lt;/panel&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pick==&lt;br /&gt;
For 3D clickable object we can use the pick-animation. It makes a whole object clickable. This is especially easy to use with switches.&lt;br /&gt;
&lt;br /&gt;
Add the following code to the .xml file of your panel. Remember to change the object-name into your buttons/knobs/switches name (!) and set the property to the property, corresponding with your button.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;animation&amp;gt;&lt;br /&gt;
  &amp;lt;type&amp;gt;pick&amp;lt;/type&amp;gt;&lt;br /&gt;
   &amp;lt;object-name&amp;gt;Seatbelt-Sign-Button&amp;lt;/object-name&amp;gt;&lt;br /&gt;
   &amp;lt;action&amp;gt;&lt;br /&gt;
    &amp;lt;button&amp;gt;0&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;repeatable&amp;gt;false&amp;lt;/repeatable&amp;gt;&lt;br /&gt;
    &amp;lt;binding&amp;gt;&lt;br /&gt;
     &amp;lt;command&amp;gt;property-toggle&amp;lt;/command&amp;gt;&lt;br /&gt;
     &amp;lt;property&amp;gt;controls/switches/seatbelt-sign&amp;lt;/property&amp;gt;&lt;br /&gt;
     &amp;lt;value&amp;gt;0&amp;lt;/value&amp;gt;&lt;br /&gt;
     &amp;lt;value&amp;gt;1&amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/binding&amp;gt;&lt;br /&gt;
   &amp;lt;/action&amp;gt;&lt;br /&gt;
 &amp;lt;/animation&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use the property-cycle command if you want to cycle through multiple values.&lt;br /&gt;
&lt;br /&gt;
If you want to have an adjustable value (like the knob on radios) you can use the property adjust command, like this:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;animation&amp;gt;&lt;br /&gt;
  &amp;lt;type&amp;gt;pick&amp;lt;/type&amp;gt;&lt;br /&gt;
   &amp;lt;object-name&amp;gt;Ingh-Knob-Right&amp;lt;/object-name&amp;gt;&lt;br /&gt;
   &amp;lt;action&amp;gt;&lt;br /&gt;
    &amp;lt;button&amp;gt;0&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;repeatable&amp;gt;false&amp;lt;/repeatable&amp;gt;&lt;br /&gt;
    &amp;lt;interval-sec&amp;gt;0.2&amp;lt;/interval-sec&amp;gt;&lt;br /&gt;
    &amp;lt;binding&amp;gt;&lt;br /&gt;
     &amp;lt;command&amp;gt;property-adjust&amp;lt;/command&amp;gt;&lt;br /&gt;
     &amp;lt;property&amp;gt;instrumentation/altimeter/setting-inhg&amp;lt;/property&amp;gt;&lt;br /&gt;
     &amp;lt;step&amp;gt;0.005&amp;lt;/step&amp;gt;&lt;br /&gt;
     &amp;lt;min&amp;gt;26.0&amp;lt;/min&amp;gt;&lt;br /&gt;
     &amp;lt;max&amp;gt;33.0&amp;lt;/max&amp;gt;&lt;br /&gt;
     &amp;lt;wrap&amp;gt;false&amp;lt;/wrap&amp;gt;&lt;br /&gt;
    &amp;lt;/binding&amp;gt;&lt;br /&gt;
   &amp;lt;/action&amp;gt;&lt;br /&gt;
 &amp;lt;/animation&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting repeatable to true will make it able to hold a knob or switch.&lt;br /&gt;
&lt;br /&gt;
To check if the pick animation works (on the correct button) we launch FlightGear and click Ctrl-C. Now all clickable objects will get a yellow lining.&lt;br /&gt;
&lt;br /&gt;
[[Category:Aircraft enhancement]]&lt;br /&gt;
[[Category:Howto|Make a clickable panel]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Blohm_%26_Voss_Bv_141&amp;diff=21349</id>
		<title>Blohm &amp; Voss Bv 141</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Blohm_%26_Voss_Bv_141&amp;diff=21349"/>
		<updated>2010-05-09T09:25:00Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* External links */ valid link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{stub}}&lt;br /&gt;
&lt;br /&gt;
 bv141: Blohm und Voss BV141&lt;br /&gt;
 bv141-yasim: Blohm und Voss BV141 (YASim)&lt;br /&gt;
 Author: BARANGER Emmanuel (3D)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== See also ===&lt;br /&gt;
*[[Table of models]]&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
*[http://helijah.free.fr/flightgear/hangar.htm Helijah's Hangar] &lt;br /&gt;
*http://www.flightgear.org/Downloads/aircraft/&lt;br /&gt;
*http://en.wikipedia.org/wiki/Blohm_%2B_Voss_BV_141&lt;br /&gt;
&lt;br /&gt;
[[Category:Aircraft]]&lt;br /&gt;
[[Category:Aircraft TODO]]s&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Dual_control&amp;diff=21266</id>
		<title>Dual control</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Dual_control&amp;diff=21266"/>
		<updated>2010-05-04T06:49:30Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Usage instruction */ typos and improve sentences&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Dual Control''' is a system for [[FlightGear]] that adds basic support for shared control of an [[aircraft]] over the FlightGear [[Multiplayer Howto|multiplayer network]].&lt;br /&gt;
&lt;br /&gt;
'''Note:''' [[FlightGear 1.9.0]] or later is needed to use Dual Control.&lt;br /&gt;
&lt;br /&gt;
==Aircraft==&lt;br /&gt;
&lt;br /&gt;
Currently there are a small number of aircraft with dual control support:&lt;br /&gt;
* [[Zeppelin NT]], pilot and copilot (&amp;lt;tt&amp;gt;ZLT-NT&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;ZLT-NT-copilot&amp;lt;/tt&amp;gt;). Available in FlightGear 1.9.0 and later.&lt;br /&gt;
* [[Blackburn Buccaneer]], pilot and systems officer (&amp;lt;tt&amp;gt;buccaneer&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;buccaneer-obs&amp;lt;/tt&amp;gt;). Available in FlightGear 1.9.0 or later.&lt;br /&gt;
* [[Grumman_F-14_Tomcat]], pilot and RIO (&amp;lt;tt&amp;gt;f-14b&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;f-14b-bs&amp;lt;/tt&amp;gt;). Available in FlightGear/CVS.&lt;br /&gt;
* [[Submarine_Scout]], pilot and observer (&amp;lt;tt&amp;gt;Submarine_Scout&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;Submarine_Scout-observer&amp;lt;/tt&amp;gt;). Available in FlightGear/CVS.&lt;br /&gt;
* [[Boeing 747-400]], pilot flying and pilot monitoring (&amp;lt;tt&amp;gt;747-400&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;747-400-fo&amp;lt;/tt&amp;gt;). Available in FlightGear/CVS.&lt;br /&gt;
* [[Storch|Fieseler Fi 156 Storch]], pilot and passenger (&amp;lt;tt&amp;gt;Fi-156-de&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;Fi-156-passenger&amp;lt;/tt&amp;gt;). Available in FlightGear/CVS.&lt;br /&gt;
* [[ASK-13 sailplane|Schleicher ASK-13 glider]], pilot and passenger (&amp;lt;tt&amp;gt;ask13&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;ask13-passenger&amp;lt;/tt&amp;gt;). Available in FlightGear/CVS.&lt;br /&gt;
* c172p Skyhawk, pilot and copilot (&amp;lt;tt&amp;gt;c172p-pilot&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;c172p-copilot&amp;lt;/tt&amp;gt;). Based on David Megginson's [[Cessna C172|c172p]] single control aircraft. Available from [http://www.gidenstam.org/FlightGear/DualControl/Aircraft the dual-control aircraft hangar]. The tar.gz archive for the aircraft should be extracted in $FG_ROOT/Aircraft/.&lt;br /&gt;
&lt;br /&gt;
To connect the pilot and copilot selects each other in the Copilot dialog (FlightGear/CVS) or set properties as explained in the usage instructions below.&lt;br /&gt;
&lt;br /&gt;
Dual control enables a pilot and copilot to jointly fly the aircraft over the FlightGear multiplayer network. Depending on the aircraft the pilot and copilot have shared control over primary flight controls, throttle, mixture and so on. Exactly which controls are shared varies between the aircraft but usually include elevator trim, flaps, brakes, cockpit switches, the radio stack and some instrument settings. The copilot usually has a subset of the full instrumentation (also depending on the aircraft), usually including airspeed, altimeter, VSI, HSI, turn coordinator, engine RPM and the radio stack. Typically Nav/Comm 1 and the first VOR indicator is best controlled by the pilot, while Nav/Comm 2 and the corresponding VOR indicator is faster for the copilot.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:ZLT-NT-dual.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
''Side-by-side presentation of the Zeppelin NT pilot's (left) and copilot's (right) views.''&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Usage instruction==&lt;br /&gt;
The system consists of two &amp;quot;aircraft&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
The pilot uses a special variant of the c172p, &amp;lt;tt&amp;gt;c172p-pilot&amp;lt;/tt&amp;gt;. The pilot needs to specify the callsign of the copilot (other copilots will be ignored).&lt;br /&gt;
For the Zeppelin NT the aircraft names are &amp;lt;tt&amp;gt;ZLT-NT&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ZLT-NT-copilot&amp;lt;/tt&amp;gt;, respectively.&lt;br /&gt;
&lt;br /&gt;
In the current version the pilot and copilot can select each other in their Co/Pilot selection dialogs available from the &amp;quot;Zeppelin NT/c172p-dual-control&amp;quot;-&amp;gt;&amp;quot;MP-(Co)Pilot&amp;quot; menus.&lt;br /&gt;
&lt;br /&gt;
Alternatively the relevant properties can be set from the command line or via the property browser.&lt;br /&gt;
&lt;br /&gt;
'''Pilot usage example:'''&lt;br /&gt;
 fgfs --aircraft=c172p-pilot --prop:/sim/remote/pilot-callsign=&amp;quot;someone&amp;quot; &lt;br /&gt;
&lt;br /&gt;
The copilot uses a special &amp;quot;aircraft&amp;quot;, c172p-copilot, which piggybacks on the designated pilot and captures the local control inputs. A current limitation is that only the cockpit views are jitter free. There is also a noticeable delay between control inputs and effect, since they are passed via the the multiplayer protocol. The severity of this delay depend on round trip time and some other factors - the delay seems significantly longer than the round trip time itself which is due to buffering in the MP protocol receiver. That said, I have flown successfully as copilot in a setup with 100-120ms round trip time between both pilot and server and copilot and server (total delay &amp;gt;500ms). Landing is a bit exciting in that case, however.&lt;br /&gt;
&lt;br /&gt;
'''Copilot usage example:'''&lt;br /&gt;
 fgfs --aircraft=c172p-copilot --prop:/sim/remote/pilot-callsign=&amp;quot;anybody&amp;quot;&lt;br /&gt;
Note: External views are jitter prone for the copilot.&lt;br /&gt;
&lt;br /&gt;
== Developer information ==&lt;br /&gt;
&lt;br /&gt;
The main part of the Dual Control system is a set of generic [[Nasal scripting language|Nasal]] modules and modified instrument files that form the core of the networked shared control functionality. See the link below for some more information.&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
&lt;br /&gt;
* [http://www.gidenstam.org/FlightGear/DualControl The main page for the Dual Control system.] Check here for the latest information.&lt;br /&gt;
&lt;br /&gt;
[[Category:FlightGear feature]]&lt;br /&gt;
&lt;br /&gt;
[[es:Control dual]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Grumman_G-21_Goose&amp;diff=21264</id>
		<title>Grumman G-21 Goose</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Grumman_G-21_Goose&amp;diff=21264"/>
		<updated>2010-05-04T03:26:46Z</updated>

		<summary type="html">&lt;p&gt;Moksha: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{infobox Aircraft&lt;br /&gt;
|image =Goose.JPG&lt;br /&gt;
|name =Grumman G21 Goose&lt;br /&gt;
|type =&lt;br /&gt;
|livery =&lt;br /&gt;
|authors =&lt;br /&gt;
|status =&lt;br /&gt;
|fdm =&lt;br /&gt;
|3dcockpit = &lt;br /&gt;
|carrier = &lt;br /&gt;
|fgname = goose&lt;br /&gt;
|download =http://www.emmerich-j.de/FGFS/Goose7.zip&lt;br /&gt;
}}&lt;br /&gt;
The '''Grumman G21 Goose''' is an eight seater amphibious aircraft, it first entered service in 1937, and saw service in WW2 with the US coastguard.&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Boeing_B-17_Flying_Fortress&amp;diff=21263</id>
		<title>Boeing B-17 Flying Fortress</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Boeing_B-17_Flying_Fortress&amp;diff=21263"/>
		<updated>2010-05-04T03:16:39Z</updated>

		<summary type="html">&lt;p&gt;Moksha: improve sentence&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{stub}}&lt;br /&gt;
{{infobox Aircraft&lt;br /&gt;
|image =B17.jpg&lt;br /&gt;
|name =B-17 Flying Fortress&lt;br /&gt;
|livery =USAAC&lt;br /&gt;
|type = 4 radial engine bomber&lt;br /&gt;
|fdm =YASim&lt;br /&gt;
|status =Development&lt;br /&gt;
|authors =Emmanuel Baranger&lt;br /&gt;
|fgname =b17&lt;br /&gt;
|download =http://helijah.free.fr/flightgear/hangar.htm&lt;br /&gt;
}}&lt;br /&gt;
The '''Boeing B-17 Flying Fortress''' is a four radial piston engine [[aircraft]] that first flew in 1935, and went on to serve as a [[:Category:Military aircraft|bomber]] in the 1940s. Some survive in flying condition into the 21st century as flying museum aircraft.&lt;br /&gt;
&lt;br /&gt;
{{Boeing}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Aircraft]]&lt;br /&gt;
[[Category:Historical aircraft]]&lt;br /&gt;
[[Category:Military aircraft]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Fokker_50&amp;diff=21262</id>
		<title>Fokker 50</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Fokker_50&amp;diff=21262"/>
		<updated>2010-05-04T03:06:48Z</updated>

		<summary type="html">&lt;p&gt;Moksha: add piped link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{non-stable}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{infobox Aircraft&lt;br /&gt;
|image =Fokker50.jpg&lt;br /&gt;
|alt =Fokker 50 in Denim Air livery&lt;br /&gt;
|name =Fokker 50&lt;br /&gt;
|type =Airliner&lt;br /&gt;
|livery=[[Air San Francisco]], Denim Air, [[:Category:Fokker|Fokker]], [[Island Virtual Airways]], KLM, VLM&lt;br /&gt;
|fdm =[[JSBSim]]&lt;br /&gt;
|status =Early-development&lt;br /&gt;
|authors =Erik Hofman, Charlie Andrews&lt;br /&gt;
|fgname =fokker50&lt;br /&gt;
}}[[Image:Fokker50_fokker.jpg|thumb|right|270px|A Fokker 50 in the manufacturer livery of Fokker.]]&lt;br /&gt;
&lt;br /&gt;
The '''Fokker 50''' is a 2 turboprop [[:Category:Airliners|airliner]].&lt;br /&gt;
&lt;br /&gt;
The first Fokker 50 can be seen at the Dutch [[Aviodrome]] museum (at [[Lelystad Airport]] in the Netherlands).&lt;br /&gt;
&lt;br /&gt;
==Aircraft help==&lt;br /&gt;
The cockpit lighting can be switched on and off on the central console.  Look down and right! That only works in [[OpenSceneGraph|OSG]], as do the other clickable cockpit objects.&lt;br /&gt;
&lt;br /&gt;
To twiddle knobs (OSG only again, I'm afraid! Use LMB to increment by 1, MMB to decrement by one. The scroll wheel increases and decreases in larger steps. At least it will if your mouse buttons are mapped in the same way that mine are! Hold the mouse cursor over the standby digits of NAV/COM/ADF boxes to adjust, then press the button to flip the freqs.  You can also adjust CDIs and the heading bug using the FMP on the glareshield.&lt;br /&gt;
&lt;br /&gt;
===Takeoff===&lt;br /&gt;
* Rotate at approx 95 kts.&lt;br /&gt;
&lt;br /&gt;
===Landing===&lt;br /&gt;
* Vref (target speed for crossing the threshold on landing) will be fine at about 95 kts again, with flap 25&lt;br /&gt;
** 35 is the max flap setting, use it for steep approaches only&lt;br /&gt;
&lt;br /&gt;
[[Image:Fokker50_KLM.jpg|thumb|270px|Fokker 50 in KLM colors.]]&lt;br /&gt;
== Development status/Issues/Todo ==&lt;br /&gt;
'''3D Cockpit:'''&lt;br /&gt;
* 3D cockpit being modelled, co-ordinated by FokkerCharlie.&lt;br /&gt;
* Some cockpit furniture still missing&lt;br /&gt;
* Power Lever quadrant not textured&lt;br /&gt;
&lt;br /&gt;
'''General:'''&lt;br /&gt;
* Engine sound in cockpit does not differ from outside engine sound&lt;br /&gt;
* Engines and props could use some tuning, prop ground range not yet modelled.&lt;br /&gt;
* Antialiasing ugliness (still) on the EFIS display.&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
The Fokker 50 FlightGear Forum threads:&lt;br /&gt;
* http://www.flightgear.org/forums/viewtopic.php?p=2691#2691&lt;br /&gt;
* http://www.flightgear.org/forums/viewtopic.php?t=345&lt;br /&gt;
&lt;br /&gt;
{{Fokker}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Aircraft]]&lt;br /&gt;
[[Category:Aircraft TODO]]&lt;br /&gt;
[[Category:Airliners]]&lt;br /&gt;
[[Category:Civilian aircraft]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=UIUC&amp;diff=21261</id>
		<title>UIUC</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=UIUC&amp;diff=21261"/>
		<updated>2010-05-04T03:03:22Z</updated>

		<summary type="html">&lt;p&gt;Moksha: spelling&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{stub}}&lt;br /&gt;
&lt;br /&gt;
'''UIUC''' is the name of a [[Flight Dynamics Model]] for [[FlightGear]] flight simulator. It was developed by the UIUC Applied Aerodynamics Group at University of Illinois at Urbana-Champaign. It was devloped in the early 2000s and has been used by many aircraft in FG. See [[Table of models]].&lt;br /&gt;
&lt;br /&gt;
UIUC made use of [[LaRCsim]] and was &amp;quot;originally developed for the [[Smart Icing System Project]]&amp;quot;  [http://www.ae.uiuc.edu/m-selig/apasim/Aircraft-uiuc.html]&lt;br /&gt;
&lt;br /&gt;
Many aircraft were worked on for FlightGear with UIUC, although many were not GPL or not maintained.  There some that that were maintained well enough to survive until [[FlightGear 1.0.0]] and expanded with new models, and even used for other FDM.&lt;br /&gt;
&lt;br /&gt;
Some UIUC v-1 aircraft include:&lt;br /&gt;
&lt;br /&gt;
*a4-v1-nl/ 	  	  	  	 &lt;br /&gt;
*airwaveXtreme150-v1-nl/ 	  	  	  	 &lt;br /&gt;
*asw20-v1-nl/ 	  	  	  	 &lt;br /&gt;
*beech99-v1/ 	  	  	  	 &lt;br /&gt;
*fkdr1-v1-nl/ 	  	  	  	 &lt;br /&gt;
*marchetti-v1/ 	  	  	  	 &lt;br /&gt;
*ornithopter/ 	  	  	  	 &lt;br /&gt;
*sopwithCamel-v1-nl/ 	  	  	  	 &lt;br /&gt;
*sopwithCamel-v2-nl/ 	  	  	  	 &lt;br /&gt;
*wrightFlyer1903-v1-nl/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
*http://www.ae.uiuc.edu/m-selig/apasim/Aircraft-uiuc.html&lt;br /&gt;
&lt;br /&gt;
{{FDM}}&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Eurocopter_EC135&amp;diff=21260</id>
		<title>Eurocopter EC135</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Eurocopter_EC135&amp;diff=21260"/>
		<updated>2010-05-03T23:28:10Z</updated>

		<summary type="html">&lt;p&gt;Moksha: minor typos and English fixes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{non-stable}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{infobox Aircraft&lt;br /&gt;
|image =Ec135.png&lt;br /&gt;
|name =Eurocopter EC135&lt;br /&gt;
|type =Helicopter&lt;br /&gt;
|livery= ADAC, ANWB, ÖAMTC, Prototype&lt;br /&gt;
|fdm =YASim&lt;br /&gt;
|status =v0.4 in 1.9.1&lt;br /&gt;
|authors =Heiko Schulz, Maik Justus, Melchior Franz&lt;br /&gt;
|fgname =&amp;lt;tt&amp;gt;ec135&amp;lt;/tt&amp;gt;&lt;br /&gt;
}}This is an model of the '''Eurocopter EC135''', a light twin-engine, multi-mission [[helicopter]]. &lt;br /&gt;
&lt;br /&gt;
Eurocopter has two version of it: the EC 135 P2i and the EC 135 T2i&lt;br /&gt;
P2 stands for the PRATT and WHITNEY PW 206B2 turbine engine with 743 PS (horsepower).&lt;br /&gt;
T2 stands for TURBOMECA Arrius 2B2 turbine engine with 706 PS.&lt;br /&gt;
The EC 135 descends from the MBB Bo 108. The Bo 108 was a demonstration prototype for fly-by-wire and has it's descent from the famous Bo 105.&lt;br /&gt;
When the Eurocopter company was founded, the Bo 108 came with.&lt;br /&gt;
Eurocopter decided that there was a marketplace for such a helicopter and the development went on.&lt;br /&gt;
From the French partners it got the fenestron, from MBB the hingeless rotor.&lt;br /&gt;
The fenestron makes it very hard for dangerous situations in the range of the tail rotor and reduces the noise level about 50% to other helicopters&lt;br /&gt;
That's why the EC 135 is a highly recommended helicopter for EMS and the police, especially in Europe but also in the USA, Japan and other states.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The models Includes the German ADAC version, the Austrian ÖAMTC version, the Dutch ANWB (Lifeliner) version and the EC135-prototype version as default&lt;br /&gt;
&lt;br /&gt;
== Development status/Issues/Todo ==&lt;br /&gt;
[[Image:Ec135_LFLJ.jpg|thumb|right|270px|EC 135 &amp;quot;D-HECZ&amp;quot; (prototype) takes off above the clouds at Courchevel; see [[Flying the helicopter]] ]]&lt;br /&gt;
&lt;br /&gt;
=== Actual version: v.0.6 (CVS)===&lt;br /&gt;
&lt;br /&gt;
* fixes wrong rotorshaft tilt in fdm&lt;br /&gt;
* some bugfixes on fuselage&lt;br /&gt;
* sound fixed&lt;br /&gt;
&lt;br /&gt;
very next To-Do:&lt;br /&gt;
* rotor model and animation&lt;br /&gt;
* bugfixing on windscreen&lt;br /&gt;
* instruments finishing&lt;br /&gt;
&lt;br /&gt;
=== Actual version: v.0.5 (CVS)===&lt;br /&gt;
&lt;br /&gt;
* photorealistic panel&lt;br /&gt;
* liveries improved&lt;br /&gt;
* better fps-perfomance while changing liveries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Actual version: v.0.4 (FGFS 1.9.1 release)===&lt;br /&gt;
&lt;br /&gt;
This is a complete rebuild of the ec135 with a much better exterior&lt;br /&gt;
model It is currently a work in progress, so a lots of things can be&lt;br /&gt;
broken now, but it should be not worser to fly than in the last version.&lt;br /&gt;
&lt;br /&gt;
* complete new exterior with added antennas and other mounting parts(search lights, cameras)&lt;br /&gt;
* glas shader with fresnel effect&lt;br /&gt;
* variants changing over mp&lt;br /&gt;
* better texture mapping so it should be easy to make your own livery&lt;br /&gt;
&lt;br /&gt;
Currently in Progress at this date:&lt;br /&gt;
* replacing the panels and adding the digital version with a nearly photorealistic one!&lt;br /&gt;
* adding the overhead&lt;br /&gt;
* making it all clickable and working from the cockpit&lt;br /&gt;
* better interior : EMS and VIP-version&lt;br /&gt;
* remade D-HECZ-Livery&lt;br /&gt;
* mapped ec135 with D-HECZ-Livery&lt;br /&gt;
* added ADAC Chr. 23-Livery made with photorealistic parts like Fenestron and Logos- still some things missing like lines&lt;br /&gt;
* added phtorealistic textures to exhaust and rails&lt;br /&gt;
* adding and finishing the missing liveries like the OEAMTC, G-SASA, Bavarian Police&lt;br /&gt;
* adding the high skid model&lt;br /&gt;
&lt;br /&gt;
=== Actual version: v.0.2 ===&lt;br /&gt;
&lt;br /&gt;
* fully new made 3D-model - matching real good to the real one&lt;br /&gt;
* improved interior with stick and pedals&lt;br /&gt;
* changed variants: ADAC Chr. 31 &amp;quot;Berlin&amp;quot;, D-HECZ &amp;quot;second prototype&amp;quot;, ÖAMTC Christopherus 1&lt;br /&gt;
* improved cockpit with half analog IFR-panel &lt;br /&gt;
* HSI is now working, working VOR&lt;br /&gt;
* GSDI selectable&lt;br /&gt;
* improved and more detailed main rotor with incidence animation&lt;br /&gt;
* Fenestron now with the correct configuration of the blades: 1-4-1-4&lt;br /&gt;
* dynamic flight model now with the correct position of the CG&lt;br /&gt;
* added frontlight, retractable landinglight, strobes with the correct frequency, beacon with the correct frequency&lt;br /&gt;
* rotor brake system now working&lt;br /&gt;
&lt;br /&gt;
To-Do:&lt;br /&gt;
* adding antennas and other mounting parts (search lights, cameras)&lt;br /&gt;
* fully clickable [[cockpit]] (half-analog and digital)&lt;br /&gt;
* complete light function&lt;br /&gt;
* variants with radardome&lt;br /&gt;
* variants with high-skid&lt;br /&gt;
* much more (international)variants! &lt;br /&gt;
* realistic dynamic flight model&lt;br /&gt;
* mainrotors much more detailed&lt;br /&gt;
* animation of the fenestron blades (incidence)&lt;br /&gt;
* sound still could be improved&lt;br /&gt;
* adding pilots figures&lt;br /&gt;
&lt;br /&gt;
=== Actual version: v.0.1 ===&lt;br /&gt;
&lt;br /&gt;
* first 3d-model of an ec135&lt;br /&gt;
* first try of an ec135-flight dynamic model&lt;br /&gt;
* livery changing&lt;br /&gt;
* two version: ADAC and Bavarian Police&lt;br /&gt;
* first version of the half analog cockpit&lt;br /&gt;
* doors to open&lt;br /&gt;
&lt;br /&gt;
To-Do:&lt;br /&gt;
* better quality of the 3d-model&lt;br /&gt;
* full mainrotor animation&lt;br /&gt;
* better Fenestron &lt;br /&gt;
* improve cockpit, implementing a working HSI&lt;br /&gt;
* clean up the xml-files&lt;br /&gt;
* improve soundsystem&lt;br /&gt;
* realistic dynamic flight model&lt;br /&gt;
* selectable GSDI&lt;br /&gt;
* implementing rotor brake system&lt;br /&gt;
* more variants&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
[http://www.eurocopter.de www.eurocopter.de]&lt;br /&gt;
&lt;br /&gt;
=== Related lists ===&lt;br /&gt;
* [[Aircraft]]&lt;br /&gt;
* [[Aircraft Todo]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Aircraft]]&lt;br /&gt;
[[Category:Helicopters]]&lt;br /&gt;
[[Category:Aircraft TODO]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Building_FlightGear_-_Debian&amp;diff=20977</id>
		<title>Building FlightGear - Debian</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Building_FlightGear_-_Debian&amp;diff=20977"/>
		<updated>2010-04-18T12:23:32Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Boost Library */typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HowTo build on Debian =&lt;br /&gt;
&lt;br /&gt;
HowTo build FlightGear 2.0.0 or CVS on GNU/Linux Debian '''Stable''' 5.x (Lenny).&lt;br /&gt;
&lt;br /&gt;
This HowTo may also work with '''Testing'''/'''Unstable''' except that some things are easier because of more up to date packages. So, before fetching something check the version of the available -dev package for it.&lt;br /&gt;
&lt;br /&gt;
It even *should* work with '''Etch''', but I am not certain about some dependencies. [http://wiki.flightgear.org/index.php?title=Talk:Building_Flightgear_-_Debian&amp;amp;action=edit Reports] are welcome.&lt;br /&gt;
&lt;br /&gt;
If you don't want to make your hands dirty, have a look at [[Scripted_Compilation_on_Linux_Debian/Ubuntu]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Requirements and Preparations ==&lt;br /&gt;
You need an OpenGL capable graphics including a proper installed driver.&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also a bunch of packages (and some of their dependencies) are required:&lt;br /&gt;
*gcc, g++, make, automake1.9, pkg-config&lt;br /&gt;
*mawk (or gawk)&lt;br /&gt;
*cmake   (min. version 2.6.0-5,  for Etch available on backports.org!)&lt;br /&gt;
*cvs, subversion, wget&lt;br /&gt;
&amp;lt;!--*libsvn-dev, for [[Terrasync]]s proper operation.--&amp;gt;&lt;br /&gt;
*freeglut3-dev, libgl1-mesa-dev, libxrandr-dev&lt;br /&gt;
*libxi-dev, libxmu-dev, libxext-dev&lt;br /&gt;
*libopenal-dev (see [[#libopenal|libopenal]]), libalut-dev&lt;br /&gt;
*libjpeg62-dev, libtiff4-dev, libpng12-dev&lt;br /&gt;
*libboost1.37-dev  (Not available for Lenny atm, see [[#Boost Library|Boost Library]] below.)&lt;br /&gt;
&lt;br /&gt;
During installation packages ''simgear-dev'' and ''openscenegraph-dev'' *must not* be installed. They can safely be re-installed after compilation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Build and install ==&lt;br /&gt;
Because we are going to install versions different to the ones in the repositries it is recommended to install FG-2.0.0 and/or CVS in a place independent to the base system such as /usr/local/FG-2.0.0, /opt/FG-2.0.0 or in a subdirectory of your $HOME. I suggest to make it writeable by the user that there is no need to become root for the &amp;lt;code&amp;gt;make install&amp;lt;/code&amp;gt; commands. I'll use &amp;lt;code&amp;gt;$prefix&amp;lt;/code&amp;gt; as a placeholder for this directory. &amp;lt;BR&amp;gt;&lt;br /&gt;
Another one will be &amp;lt;code&amp;gt;$srcdir&amp;lt;/code&amp;gt;, it stands for the absolute path to the directory which contains the folders of the various source codes. So in the following instructions one have to replace these by the local paths or even &amp;lt;code&amp;gt;export&amp;lt;/code&amp;gt; them during the process.&lt;br /&gt;
&lt;br /&gt;
Subsequent the instructions to fetch the sources and the data needed by FlightGear and the commands to build/install each source.&lt;br /&gt;
&lt;br /&gt;
Have in mind that the data is relatively huge (CVS about 2 GB and 2.0.0 300 MB) so, to save some time, it is a good idea to fetch it while building the sources.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== libopenal ===&lt;br /&gt;
The libopenal-dev package in Lenny/Etch is too old for [[fgcom]]. For FlightGear it does work but not all features (like Doppler) are available, so installing an up to date version is recommended anyway.&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 wget http://kcat.strangesoft.net/openal-releases/openal-soft-1.11.753.tar.bz2&lt;br /&gt;
 tar xjf openal-soft-1.11.753.tar.bz2&lt;br /&gt;
 cd openal-soft-1.11.753/build&lt;br /&gt;
 cmake  -D CMAKE_INSTALL_PREFIX:PATH=&amp;quot;$prefix&amp;quot; ..&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== plib ===&lt;br /&gt;
Latest SVN is [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg20793.html recommended], yet package plib1.8.5-dev for Testing/Unstable does work as well.&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co https://plib.svn.sourceforge.net/svnroot/plib/trunk plib&lt;br /&gt;
 cd plib&lt;br /&gt;
 sed s/PLIB_TINY_VERSION\ \ 5/PLIB_TINY_VERSION\ \ 6/ -i src/util/ul.h&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
 ./configure --prefix=$prefix&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Boost Library ===&lt;br /&gt;
Version 1.37 is needed. At least for Lenny/Etch this means getting the sources because this is not available atm on backports.org. Testing/Unstable users may have more luck and a package is available, libboost-1.37-dev or newer.&lt;br /&gt;
&lt;br /&gt;
To build SimGear, FlightGear, fgrun and fgcom some boostlib header files are required, no need to compile and install it. If you have installed a libboost1.37-dev (or higher) package on your system you don't have to bother at all with it. If not, you have to tell each ./configure where the header files are. To do so, add the option &amp;lt;code&amp;gt;CPPFLAGS=-I$prefix/include&amp;lt;/code&amp;gt; to the SimGear, FlightGear and fgrun &amp;lt;code&amp;gt;./configure&amp;lt;/code&amp;gt; commands. We copy the header files to $prefix/include because fgcom will need them there.&lt;br /&gt;
&lt;br /&gt;
Get the newest version tar ball from http://sourceforge.net/projects/boost/files/boost/, extract it into &amp;lt;code&amp;gt;$srcdir&amp;lt;/code&amp;gt; then:&lt;br /&gt;
 cp -R $srcdir/boost-[version]/boost/ $prefix/include/&lt;br /&gt;
&lt;br /&gt;
=== OpenSceneGraph ===&lt;br /&gt;
For FlightGear 2.0.0 one may use the latest (or at least 2.9.6) developer release from http://www.openscenegraph.org/projects/osg/wiki/Downloads/DeveloperReleases and extract it into &amp;lt;code&amp;gt;$srcdir&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Mostly this is ok for FlightGear CVS as well as it is stable. However, sometimes the release is not fresh enough and one have to get the latest developments via SVN:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co http://www.openscenegraph.org/svn/osg/OpenSceneGraph/trunk OpenSceneGraph&lt;br /&gt;
&lt;br /&gt;
cmake demands a build directory separate to its source directory. So &amp;lt;code&amp;gt;mkdir&amp;lt;/code&amp;gt; one and &amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; into it.&lt;br /&gt;
 cmake -D CMAKE_BUILD_TYPE=&amp;quot;Release&amp;quot; -D CMAKE_CXX_FLAGS=&amp;quot;-O3&amp;quot; -D CMAKE_C_FLAGS=&amp;quot;-O3&amp;quot; \&lt;br /&gt;
    -D CMAKE_INSTALL_PREFIX:PATH=&amp;quot;$prefix&amp;quot; $srcdir/OpenSceneGraph[-version]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== SimGear ===&lt;br /&gt;
2.0.0:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 wget http://mirrors.ibiblio.org/pub/mirrors/simgear/ftp/Source/SimGear-2.0.0.tar.gz&lt;br /&gt;
 tar xzf SimGear-2.0.0.tar.gz&lt;br /&gt;
 cd SimGear-2.0.0&lt;br /&gt;
&lt;br /&gt;
CVS:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 mkdir simgear&lt;br /&gt;
 cd simgear&lt;br /&gt;
 cvs -d :pserver:cvsguest@cvs.simgear.org:/var/cvs/SimGear-0.3 login&lt;br /&gt;
 #CVS passwd: guest&lt;br /&gt;
 cvs -d :pserver:cvsguest@cvs.simgear.org:/var/cvs/SimGear-0.3 co source&lt;br /&gt;
 cd source&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
&lt;br /&gt;
2.0.0 and CVS:&lt;br /&gt;
 ./configure --prefix=$prefix [CPPFLAGS=-I$prefix/include LDFLAGS=&amp;quot;-L$prefix/lib -L$prefix/lib64&amp;quot;]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== FlightGear source ===&lt;br /&gt;
2.0.0:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 wget http://mirrors.ibiblio.org/pub/mirrors/flightgear/ftp/Source/FlightGear-2.0.0.tar.gz&lt;br /&gt;
 tar xzf FlightGear-2.0.0.tar.gz&lt;br /&gt;
 cd FlightGear-2.0.0&lt;br /&gt;
&lt;br /&gt;
CVS:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 mkdir flightgear&lt;br /&gt;
 cd flightgear&lt;br /&gt;
 cvs -d :pserver:cvsguest@cvs.flightgear.org:/var/cvs/FlightGear-0.9 login&lt;br /&gt;
 #CVS passwd: guest&lt;br /&gt;
 cvs -d :pserver:cvsguest@cvs.flightgear.org:/var/cvs/FlightGear-0.9 co source&lt;br /&gt;
 cd source&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
&lt;br /&gt;
2.0.0 and CVS:&lt;br /&gt;
 ./configure --prefix=$prefix [CPPFLAGS=-I$prefix/include/ LDFLAGS=&amp;quot;-L$prefix/lib -L$prefix/lib64&amp;quot;]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== FlightGear data ===&lt;br /&gt;
2.0.0:&lt;br /&gt;
 cd $prefix&lt;br /&gt;
 wget http://mirrors.ibiblio.org/pub/mirrors/flightgear/ftp/Shared/FlightGear-data-2.0.0.tar.bz2&lt;br /&gt;
 tar xjf FlightGear-data-2.0.0.tar.bz2&lt;br /&gt;
&lt;br /&gt;
CVS:&lt;br /&gt;
 cd $prefix&lt;br /&gt;
 cvs -d :pserver:cvsguest@cvs.flightgear.org:/var/cvs/FlightGear-0.9 co data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Trial run ===&lt;br /&gt;
When all the builds are done and the data download has finished it is time for a test run:&lt;br /&gt;
 export LD_LIBRARY_PATH=$prefix/lib/:$LD_LIBRARY_PATH&lt;br /&gt;
 $prefix/bin/fgfs --fg-root=$prefix/data&lt;br /&gt;
&lt;br /&gt;
For the future, if you want to start FlightGear from command line have a look at [[fgfsrc]], if you prefer a graphical user interface continue with [[#fgrun|compiling fgrun]]. Have in mind that fgfs need to find our self compiled libraries and therefore we have to tell the linker (ld) where to find them. That is what the first line here does.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Optional Software ==&lt;br /&gt;
&lt;br /&gt;
=== fgrun ===&lt;br /&gt;
To build [[fgrun]] two more package is required:&lt;br /&gt;
*libfltk1.1-dev fluid&lt;br /&gt;
&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co http://fgrun.svn.sourceforge.net/svnroot/fgrun/trunk fgrun&lt;br /&gt;
 cd fgrun&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
 ./configure --prefix=$prefix  [CPPFLAGS=-I$prefix/include/]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== fgcom ===&lt;br /&gt;
For [[fgcom]] unfortunately there is one more dependency which cannot be solved with packages on Lenny/Etch, see [[#libopenal|libopenal]].&lt;br /&gt;
&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co https://appfgcom.svn.sourceforge.net/svnroot/fgcom/trunk fgcom&lt;br /&gt;
 cd fgcom/src&lt;br /&gt;
 make INSTALL_BIN=$prefix/bin INSTALL_DIR=$prefix/fgcom \&lt;br /&gt;
    PLIB_PREFIX=$prefix OPENAL_PREFIX=$prefix install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--== Keeping the CVS version up to date ==&lt;br /&gt;
&lt;br /&gt;
...to be continued. ;-)&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Building}}&lt;br /&gt;
&lt;br /&gt;
[[de:FlightGear_bauen_-_Debian]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Building_FlightGear_-_Debian&amp;diff=20976</id>
		<title>Building FlightGear - Debian</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Building_FlightGear_-_Debian&amp;diff=20976"/>
		<updated>2010-04-18T12:22:26Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* libopenal */ typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HowTo build on Debian =&lt;br /&gt;
&lt;br /&gt;
HowTo build FlightGear 2.0.0 or CVS on GNU/Linux Debian '''Stable''' 5.x (Lenny).&lt;br /&gt;
&lt;br /&gt;
This HowTo may also work with '''Testing'''/'''Unstable''' except that some things are easier because of more up to date packages. So, before fetching something check the version of the available -dev package for it.&lt;br /&gt;
&lt;br /&gt;
It even *should* work with '''Etch''', but I am not certain about some dependencies. [http://wiki.flightgear.org/index.php?title=Talk:Building_Flightgear_-_Debian&amp;amp;action=edit Reports] are welcome.&lt;br /&gt;
&lt;br /&gt;
If you don't want to make your hands dirty, have a look at [[Scripted_Compilation_on_Linux_Debian/Ubuntu]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Requirements and Preparations ==&lt;br /&gt;
You need an OpenGL capable graphics including a proper installed driver.&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also a bunch of packages (and some of their dependencies) are required:&lt;br /&gt;
*gcc, g++, make, automake1.9, pkg-config&lt;br /&gt;
*mawk (or gawk)&lt;br /&gt;
*cmake   (min. version 2.6.0-5,  for Etch available on backports.org!)&lt;br /&gt;
*cvs, subversion, wget&lt;br /&gt;
&amp;lt;!--*libsvn-dev, for [[Terrasync]]s proper operation.--&amp;gt;&lt;br /&gt;
*freeglut3-dev, libgl1-mesa-dev, libxrandr-dev&lt;br /&gt;
*libxi-dev, libxmu-dev, libxext-dev&lt;br /&gt;
*libopenal-dev (see [[#libopenal|libopenal]]), libalut-dev&lt;br /&gt;
*libjpeg62-dev, libtiff4-dev, libpng12-dev&lt;br /&gt;
*libboost1.37-dev  (Not available for Lenny atm, see [[#Boost Library|Boost Library]] below.)&lt;br /&gt;
&lt;br /&gt;
During installation packages ''simgear-dev'' and ''openscenegraph-dev'' *must not* be installed. They can safely be re-installed after compilation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Build and install ==&lt;br /&gt;
Because we are going to install versions different to the ones in the repositries it is recommended to install FG-2.0.0 and/or CVS in a place independent to the base system such as /usr/local/FG-2.0.0, /opt/FG-2.0.0 or in a subdirectory of your $HOME. I suggest to make it writeable by the user that there is no need to become root for the &amp;lt;code&amp;gt;make install&amp;lt;/code&amp;gt; commands. I'll use &amp;lt;code&amp;gt;$prefix&amp;lt;/code&amp;gt; as a placeholder for this directory. &amp;lt;BR&amp;gt;&lt;br /&gt;
Another one will be &amp;lt;code&amp;gt;$srcdir&amp;lt;/code&amp;gt;, it stands for the absolute path to the directory which contains the folders of the various source codes. So in the following instructions one have to replace these by the local paths or even &amp;lt;code&amp;gt;export&amp;lt;/code&amp;gt; them during the process.&lt;br /&gt;
&lt;br /&gt;
Subsequent the instructions to fetch the sources and the data needed by FlightGear and the commands to build/install each source.&lt;br /&gt;
&lt;br /&gt;
Have in mind that the data is relatively huge (CVS about 2 GB and 2.0.0 300 MB) so, to save some time, it is a good idea to fetch it while building the sources.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== libopenal ===&lt;br /&gt;
The libopenal-dev package in Lenny/Etch is too old for [[fgcom]]. For FlightGear it does work but not all features (like Doppler) are available, so installing an up to date version is recommended anyway.&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 wget http://kcat.strangesoft.net/openal-releases/openal-soft-1.11.753.tar.bz2&lt;br /&gt;
 tar xjf openal-soft-1.11.753.tar.bz2&lt;br /&gt;
 cd openal-soft-1.11.753/build&lt;br /&gt;
 cmake  -D CMAKE_INSTALL_PREFIX:PATH=&amp;quot;$prefix&amp;quot; ..&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== plib ===&lt;br /&gt;
Latest SVN is [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg20793.html recommended], yet package plib1.8.5-dev for Testing/Unstable does work as well.&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co https://plib.svn.sourceforge.net/svnroot/plib/trunk plib&lt;br /&gt;
 cd plib&lt;br /&gt;
 sed s/PLIB_TINY_VERSION\ \ 5/PLIB_TINY_VERSION\ \ 6/ -i src/util/ul.h&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
 ./configure --prefix=$prefix&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Boost Library ===&lt;br /&gt;
Version 1.37 is needed. At least for Lenny/Etch this means getting the sources because this is not available atm on backports.org. Testing/Unstable users may have more luck and a package is available, libboost-1.37-dev or newer.&lt;br /&gt;
&lt;br /&gt;
To build SimGear, FlightGear, fgrun and fgcom some boostlib header files are required, no need to compile and install it. If you have installed a libboost1.37-dev (or highter) package on your system you don't have to bother at all with it. If not, you have to tell each ./configure where the header files are. To do so, add the option &amp;lt;code&amp;gt;CPPFLAGS=-I$prefix/include&amp;lt;/code&amp;gt; to the SimGear, FlightGear and fgrun &amp;lt;code&amp;gt;./configure&amp;lt;/code&amp;gt; commands. We copy the header files to $prefix/include because fgcom will need them there.&lt;br /&gt;
&lt;br /&gt;
Get the newest version tar ball from http://sourceforge.net/projects/boost/files/boost/, extract it into &amp;lt;code&amp;gt;$srcdir&amp;lt;/code&amp;gt; then:&lt;br /&gt;
 cp -R $srcdir/boost-[version]/boost/ $prefix/include/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== OpenSceneGraph ===&lt;br /&gt;
For FlightGear 2.0.0 one may use the latest (or at least 2.9.6) developer release from http://www.openscenegraph.org/projects/osg/wiki/Downloads/DeveloperReleases and extract it into &amp;lt;code&amp;gt;$srcdir&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Mostly this is ok for FlightGear CVS as well as it is stable. However, sometimes the release is not fresh enough and one have to get the latest developments via SVN:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co http://www.openscenegraph.org/svn/osg/OpenSceneGraph/trunk OpenSceneGraph&lt;br /&gt;
&lt;br /&gt;
cmake demands a build directory separate to its source directory. So &amp;lt;code&amp;gt;mkdir&amp;lt;/code&amp;gt; one and &amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; into it.&lt;br /&gt;
 cmake -D CMAKE_BUILD_TYPE=&amp;quot;Release&amp;quot; -D CMAKE_CXX_FLAGS=&amp;quot;-O3&amp;quot; -D CMAKE_C_FLAGS=&amp;quot;-O3&amp;quot; \&lt;br /&gt;
    -D CMAKE_INSTALL_PREFIX:PATH=&amp;quot;$prefix&amp;quot; $srcdir/OpenSceneGraph[-version]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== SimGear ===&lt;br /&gt;
2.0.0:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 wget http://mirrors.ibiblio.org/pub/mirrors/simgear/ftp/Source/SimGear-2.0.0.tar.gz&lt;br /&gt;
 tar xzf SimGear-2.0.0.tar.gz&lt;br /&gt;
 cd SimGear-2.0.0&lt;br /&gt;
&lt;br /&gt;
CVS:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 mkdir simgear&lt;br /&gt;
 cd simgear&lt;br /&gt;
 cvs -d :pserver:cvsguest@cvs.simgear.org:/var/cvs/SimGear-0.3 login&lt;br /&gt;
 #CVS passwd: guest&lt;br /&gt;
 cvs -d :pserver:cvsguest@cvs.simgear.org:/var/cvs/SimGear-0.3 co source&lt;br /&gt;
 cd source&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
&lt;br /&gt;
2.0.0 and CVS:&lt;br /&gt;
 ./configure --prefix=$prefix [CPPFLAGS=-I$prefix/include LDFLAGS=&amp;quot;-L$prefix/lib -L$prefix/lib64&amp;quot;]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== FlightGear source ===&lt;br /&gt;
2.0.0:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 wget http://mirrors.ibiblio.org/pub/mirrors/flightgear/ftp/Source/FlightGear-2.0.0.tar.gz&lt;br /&gt;
 tar xzf FlightGear-2.0.0.tar.gz&lt;br /&gt;
 cd FlightGear-2.0.0&lt;br /&gt;
&lt;br /&gt;
CVS:&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 mkdir flightgear&lt;br /&gt;
 cd flightgear&lt;br /&gt;
 cvs -d :pserver:cvsguest@cvs.flightgear.org:/var/cvs/FlightGear-0.9 login&lt;br /&gt;
 #CVS passwd: guest&lt;br /&gt;
 cvs -d :pserver:cvsguest@cvs.flightgear.org:/var/cvs/FlightGear-0.9 co source&lt;br /&gt;
 cd source&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
&lt;br /&gt;
2.0.0 and CVS:&lt;br /&gt;
 ./configure --prefix=$prefix [CPPFLAGS=-I$prefix/include/ LDFLAGS=&amp;quot;-L$prefix/lib -L$prefix/lib64&amp;quot;]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== FlightGear data ===&lt;br /&gt;
2.0.0:&lt;br /&gt;
 cd $prefix&lt;br /&gt;
 wget http://mirrors.ibiblio.org/pub/mirrors/flightgear/ftp/Shared/FlightGear-data-2.0.0.tar.bz2&lt;br /&gt;
 tar xjf FlightGear-data-2.0.0.tar.bz2&lt;br /&gt;
&lt;br /&gt;
CVS:&lt;br /&gt;
 cd $prefix&lt;br /&gt;
 cvs -d :pserver:cvsguest@cvs.flightgear.org:/var/cvs/FlightGear-0.9 co data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Trial run ===&lt;br /&gt;
When all the builds are done and the data download has finished it is time for a test run:&lt;br /&gt;
 export LD_LIBRARY_PATH=$prefix/lib/:$LD_LIBRARY_PATH&lt;br /&gt;
 $prefix/bin/fgfs --fg-root=$prefix/data&lt;br /&gt;
&lt;br /&gt;
For the future, if you want to start FlightGear from command line have a look at [[fgfsrc]], if you prefer a graphical user interface continue with [[#fgrun|compiling fgrun]]. Have in mind that fgfs need to find our self compiled libraries and therefore we have to tell the linker (ld) where to find them. That is what the first line here does.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Optional Software ==&lt;br /&gt;
&lt;br /&gt;
=== fgrun ===&lt;br /&gt;
To build [[fgrun]] two more package is required:&lt;br /&gt;
*libfltk1.1-dev fluid&lt;br /&gt;
&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co http://fgrun.svn.sourceforge.net/svnroot/fgrun/trunk fgrun&lt;br /&gt;
 cd fgrun&lt;br /&gt;
 ./autogen.sh&lt;br /&gt;
 ./configure --prefix=$prefix  [CPPFLAGS=-I$prefix/include/]&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== fgcom ===&lt;br /&gt;
For [[fgcom]] unfortunately there is one more dependency which cannot be solved with packages on Lenny/Etch, see [[#libopenal|libopenal]].&lt;br /&gt;
&lt;br /&gt;
 cd $srcdir&lt;br /&gt;
 svn co https://appfgcom.svn.sourceforge.net/svnroot/fgcom/trunk fgcom&lt;br /&gt;
 cd fgcom/src&lt;br /&gt;
 make INSTALL_BIN=$prefix/bin INSTALL_DIR=$prefix/fgcom \&lt;br /&gt;
    PLIB_PREFIX=$prefix OPENAL_PREFIX=$prefix install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--== Keeping the CVS version up to date ==&lt;br /&gt;
&lt;br /&gt;
...to be continued. ;-)&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Building}}&lt;br /&gt;
&lt;br /&gt;
[[de:FlightGear_bauen_-_Debian]]&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Scripted_Compilation_on_Linux_Debian/Ubuntu&amp;diff=20975</id>
		<title>Scripted Compilation on Linux Debian/Ubuntu</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Scripted_Compilation_on_Linux_Debian/Ubuntu&amp;diff=20975"/>
		<updated>2010-04-18T11:54:49Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Launching Fgrun */ typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Description==&lt;br /&gt;
The following script takes care of downloading and compiling Flightgear from the cvs repositories with just one command execution for both 32-bit and 64-bit Debian based systems (Debian, Ubuntu). Pre-existing installed version (if any) of Flightgear are not touched at all since the script builds and installs everything under the directory in which it is launched.&lt;br /&gt;
&lt;br /&gt;
Necessary packages are installed via the apt-get system while libraries not included in the repositories are downloaded and compiled on the fly (i.e. [[Plib]], [[Simgear]] and [[OSG]]).&lt;br /&gt;
&lt;br /&gt;
===List of compiled programs===&lt;br /&gt;
The script is able to download and compile:&lt;br /&gt;
* Flightgear  (And all the data needed to use it)&lt;br /&gt;
* [[Fgrun]]&lt;br /&gt;
* [[FGCOM]]&lt;br /&gt;
* [[Atlas]]&lt;br /&gt;
* [[Terrasync]]&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
You can download the script here: [[http://brisa.homelinux.net/fgfs/download_and_compile.sh download_and_compile.sh]]&lt;br /&gt;
&lt;br /&gt;
The script is hosted on a home server, so if the electricity goes down or internet connection fails, you will be not able to download it directly.&lt;br /&gt;
[[http://www.rato.us/flightgear/download_and_compile.sh A backup is here]]&lt;br /&gt;
&lt;br /&gt;
If all else fails, join the [[FlightGear IRC channel]] and ask for the download_and_compile.sh script. Someone there will be likely to provide it to you.&lt;br /&gt;
&lt;br /&gt;
==Instructions==&lt;br /&gt;
To run download_and_compile.sh, just save it in a directory called for example: ~/fg_tools&lt;br /&gt;
then execute it (no need to execute it as root).&lt;br /&gt;
&lt;br /&gt;
Here is for example a sequence of commands to get the script and launch it in a new folder.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir ~/fgfs&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
wget http://brisa.homelinux.net/fgfs/download_and_compile.sh&lt;br /&gt;
chmod 755 download_and_compile.sh&lt;br /&gt;
sh download_and_compile.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once all will be finished, you will sucessfully get all the programs installed in the ~/fgfs directory.&lt;br /&gt;
&lt;br /&gt;
===Launching FlightGear===&lt;br /&gt;
To run your new cvs installation of Flightgear you have to launch the ''run_fgfs.sh'' command under the same folder, for example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_fgfs.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Launching Fgrun===&lt;br /&gt;
For many users it's more comfortable having Flightgear launched by the graphical utiliy Fgrun which is installed as well in the same folder. You have to launch the ''run_fgrun.sh'' command, for example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_fgrun.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Launching FGCOM===&lt;br /&gt;
FGCOM is the system used by flightgear to simulate radio communications between users. Launch it using the ''run_fgcom.sh'' command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_fgcom.sh -cs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Launching Atlas===&lt;br /&gt;
Atlas provides a map for Flightgear, use it launching: ''run_atlas.sh''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_fgatlas.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Launching Terrasync===&lt;br /&gt;
Your Flightgear compilation comes with the Terrasync program too, so if you want to use it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_terrasync.sh -p 5500 -d /folder/with/sceneries&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Where: ''/folder/with/sceneries'' is the folder containing the sceneries data.&lt;br /&gt;
&lt;br /&gt;
Then launch fgfs with the  '''--fg-scenery=/folder/with/sceneries --atlas=socket,out,5,localhost,5500,udp'''   option&lt;br /&gt;
&lt;br /&gt;
==Troubleshooting==&lt;br /&gt;
&lt;br /&gt;
===Compilation errors===&lt;br /&gt;
Here we are, no fear, if you wish to use programs from the cvs/svn repositories, you might face compilation errors that will prevent you to have a working copy of one or more of the programs provided by this script. What can be the causes that prevent us from a successful compiling? As far as I know those:&lt;br /&gt;
# Software developers introduce a new functionality with a new piece of code that prevents the compilation under your architecture, this can happen working with cvs/svn sources.&lt;br /&gt;
# The program refuses to compile because of a divergence in the libraries it depends. For example Flightgear might not compile because OSG has been modified, while OSG itself compiles fine, FG won't.&lt;br /&gt;
# One or more repositories are down and you can't get the library you need. (Both from cvs/svn or apt-get)&lt;br /&gt;
&lt;br /&gt;
There is a simple solution to the above errors: wait and relaunch the script after some time (hours or days), if (and generally happens) software developers repair or synchronize their code with the newly updated libraries, your Flightgear will compile fine as if the previous error never took place.&lt;br /&gt;
&lt;br /&gt;
Sometimes it happens that the script fails to compile only fgrun,fgcom or atlas, if you then see the run_fgfs.sh file it means that Flightgear installation was successful and you can safely run it.&lt;br /&gt;
&lt;br /&gt;
==Options==&lt;br /&gt;
The script by default (without any option) will only compile Flightgear and Fgrun. To make it compile all, you need to launch the script with the ''ALL'' parameter. i.e.:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sh download_and_compile.sh ALL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Compiling only one program===&lt;br /&gt;
If you wish to recompile only one of the programs you can launch the script with one of the following parameters:&lt;br /&gt;
* PLIB (to compile and install only plib)&lt;br /&gt;
* OSG (to compile and install only OpenSceneGraph)&lt;br /&gt;
* SIMGEAR (to compile and install only Simgear)&lt;br /&gt;
* FGFS (to compile and install only FlightGear)&lt;br /&gt;
* DATA (to download / update only data files for FlightGear)&lt;br /&gt;
* FGRUN (to compile and install only Fgrun)&lt;br /&gt;
* FGCOM (to compile and install only Fgcom)&lt;br /&gt;
* ATLAS (to compile and install only Atlas)&lt;br /&gt;
&lt;br /&gt;
===Fast updating===&lt;br /&gt;
There is a second parameter ''UPDATE'' that allows you to just update your installation. i.e.:&lt;br /&gt;
This will only update FGFS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sh download_and_compile.sh FGFS UPDATE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Advanced options===&lt;br /&gt;
* Skip download of packages using '''-p n''' option&lt;br /&gt;
* Skip compilation of programs using '''-c n''' option&lt;br /&gt;
* Skip retrieving software updates using '''-d n''' option&lt;br /&gt;
* Skip reconfigure (make clean) using '''-r n''' option&lt;br /&gt;
&lt;br /&gt;
For example, if you a developer and wish to fast recompile and reinstall only modification for FlightGear do this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sh download_and_compile.sh -p n -d n -r n  FGFS&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
this will only recompile modifications and reinstall them.&lt;br /&gt;
&lt;br /&gt;
==Disk usage==&lt;br /&gt;
Having both compiled program, source codes and data from cvs requires some hard disk space: It will take you something like 3GB of space.&lt;br /&gt;
If you don't have a fast machine, it will require you also some hours of compilation time.&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Scripted_Compilation_on_Linux_Debian/Ubuntu&amp;diff=20974</id>
		<title>Scripted Compilation on Linux Debian/Ubuntu</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Scripted_Compilation_on_Linux_Debian/Ubuntu&amp;diff=20974"/>
		<updated>2010-04-18T07:59:19Z</updated>

		<summary type="html">&lt;p&gt;Moksha: /* Launching Fgrun */ correct spelling&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Description==&lt;br /&gt;
The following script takes care of downloading and compiling Flightgear from the cvs repositories with just one command execution for both 32-bit and 64-bit Debian based systems (Debian, Ubuntu). Pre-existing installed version (if any) of Flightgear are not touched at all since the script builds and installs everything under the directory in which it is launched.&lt;br /&gt;
&lt;br /&gt;
Necessary packages are installed via the apt-get system while libraries not included in the repositories are downloaded and compiled on the fly (i.e. [[Plib]], [[Simgear]] and [[OSG]]).&lt;br /&gt;
&lt;br /&gt;
===List of compiled programs===&lt;br /&gt;
The script is able to download and compile:&lt;br /&gt;
* Flightgear  (And all the data needed to use it)&lt;br /&gt;
* [[Fgrun]]&lt;br /&gt;
* [[FGCOM]]&lt;br /&gt;
* [[Atlas]]&lt;br /&gt;
* [[Terrasync]]&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
You can download the script here: [[http://brisa.homelinux.net/fgfs/download_and_compile.sh download_and_compile.sh]]&lt;br /&gt;
&lt;br /&gt;
The script is hosted on a home server, so if the electricity goes down or internet connection fails, you will be not able to download it directly.&lt;br /&gt;
[[http://www.rato.us/flightgear/download_and_compile.sh A backup is here]]&lt;br /&gt;
&lt;br /&gt;
If all else fails, join the [[FlightGear IRC channel]] and ask for the download_and_compile.sh script. Someone there will be likely to provide it to you.&lt;br /&gt;
&lt;br /&gt;
==Instructions==&lt;br /&gt;
To run download_and_compile.sh, just save it in a directory called for example: ~/fg_tools&lt;br /&gt;
then execute it (no need to execute it as root).&lt;br /&gt;
&lt;br /&gt;
Here is for example a sequence of commands to get the script and launch it in a new folder.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir ~/fgfs&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
wget http://brisa.homelinux.net/fgfs/download_and_compile.sh&lt;br /&gt;
chmod 755 download_and_compile.sh&lt;br /&gt;
sh download_and_compile.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once all will be finished, you will sucessfully get all the programs installed in the ~/fgfs directory.&lt;br /&gt;
&lt;br /&gt;
===Launching FlightGear===&lt;br /&gt;
To run your new cvs installation of Flightgear you have to launch the ''run_fgfs.sh'' command under the same folder, for example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_fgfs.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Launching Fgrun===&lt;br /&gt;
For many users it's more comfortable having Flighgear launched by the graphical utiliy Fgrun which is installed as well in the same folder. You have to launch the ''run_fgrun.sh'' command, for example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_fgrun.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Launching FGCOM===&lt;br /&gt;
FGCOM is the system used by flightgear to simulate radio communications between users. Launch it using the ''run_fgcom.sh'' command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_fgcom.sh -cs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Launching Atlas===&lt;br /&gt;
Atlas provides a map for Flightgear, use it launching: ''run_atlas.sh''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_fgatlas.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Launching Terrasync===&lt;br /&gt;
Your Flightgear compilation comes with the Terrasync program too, so if you want to use it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ~/fgfs&lt;br /&gt;
sh run_terrasync.sh -p 5500 -d /folder/with/sceneries&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Where: ''/folder/with/sceneries'' is the folder containing the sceneries data.&lt;br /&gt;
&lt;br /&gt;
Then launch fgfs with the  '''--fg-scenery=/folder/with/sceneries --atlas=socket,out,5,localhost,5500,udp'''   option&lt;br /&gt;
&lt;br /&gt;
==Troubleshooting==&lt;br /&gt;
&lt;br /&gt;
===Compilation errors===&lt;br /&gt;
Here we are, no fear, if you wish to use programs from the cvs/svn repositories, you might face compilation errors that will prevent you to have a working copy of one or more of the programs provided by this script. What can be the causes that prevent us from a successful compiling? As far as I know those:&lt;br /&gt;
# Software developers introduce a new functionality with a new piece of code that prevents the compilation under your architecture, this can happen working with cvs/svn sources.&lt;br /&gt;
# The program refuses to compile because of a divergence in the libraries it depends. For example Flightgear might not compile because OSG has been modified, while OSG itself compiles fine, FG won't.&lt;br /&gt;
# One or more repositories are down and you can't get the library you need. (Both from cvs/svn or apt-get)&lt;br /&gt;
&lt;br /&gt;
There is a simple solution to the above errors: wait and relaunch the script after some time (hours or days), if (and generally happens) software developers repair or synchronize their code with the newly updated libraries, your Flightgear will compile fine as if the previous error never took place.&lt;br /&gt;
&lt;br /&gt;
Sometimes it happens that the script fails to compile only fgrun,fgcom or atlas, if you then see the run_fgfs.sh file it means that Flightgear installation was successful and you can safely run it.&lt;br /&gt;
&lt;br /&gt;
==Options==&lt;br /&gt;
The script by default (without any option) will only compile Flightgear and Fgrun. To make it compile all, you need to launch the script with the ''ALL'' parameter. i.e.:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sh download_and_compile.sh ALL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Compiling only one program===&lt;br /&gt;
If you wish to recompile only one of the programs you can launch the script with one of the following parameters:&lt;br /&gt;
* PLIB (to compile and install only plib)&lt;br /&gt;
* OSG (to compile and install only OpenSceneGraph)&lt;br /&gt;
* SIMGEAR (to compile and install only Simgear)&lt;br /&gt;
* FGFS (to compile and install only FlightGear)&lt;br /&gt;
* DATA (to download / update only data files for FlightGear)&lt;br /&gt;
* FGRUN (to compile and install only Fgrun)&lt;br /&gt;
* FGCOM (to compile and install only Fgcom)&lt;br /&gt;
* ATLAS (to compile and install only Atlas)&lt;br /&gt;
&lt;br /&gt;
===Fast updating===&lt;br /&gt;
There is a second parameter ''UPDATE'' that allows you to just update your installation. i.e.:&lt;br /&gt;
This will only update FGFS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sh download_and_compile.sh FGFS UPDATE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Advanced options===&lt;br /&gt;
* Skip download of packages using '''-p n''' option&lt;br /&gt;
* Skip compilation of programs using '''-c n''' option&lt;br /&gt;
* Skip retrieving software updates using '''-d n''' option&lt;br /&gt;
* Skip reconfigure (make clean) using '''-r n''' option&lt;br /&gt;
&lt;br /&gt;
For example, if you a developer and wish to fast recompile and reinstall only modification for FlightGear do this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sh download_and_compile.sh -p n -d n -r n  FGFS&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
this will only recompile modifications and reinstall them.&lt;br /&gt;
&lt;br /&gt;
==Disk usage==&lt;br /&gt;
Having both compiled program, source codes and data from cvs requires some hard disk space: It will take you something like 3GB of space.&lt;br /&gt;
If you don't have a fast machine, it will require you also some hours of compilation time.&lt;/div&gt;</summary>
		<author><name>Moksha</name></author>
	</entry>
</feed>