Nasal scripting language: Difference between revisions

Jump to navigation Jump to search
Line 61: Line 61:
{{Template:Nasal Navigation}}
{{Template:Nasal Navigation}}


==Namespaces==
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 "sub module" share a single name space based on the folder's name rather than the name of the individual Nasal files.
For cases of Nasal code specific for an aircraft (like instruments, for example), the corresponding scripts could be loaded through the aircraft's <tt>-set.xml</tt> file by putting it into the <tt><nasal>...</nasal><tt> section
<syntaxhighlight lang="xml">
  <nasal>
    ...
    <moduleA>
      <file>path/to/file1.nas</file>
      <file>path/to/file2.nas</file>
    </moduleA>
    <moduleB>
      <file>path/to/file3.nas</file>
    </moduleB>
  </nasal>
</syntaxhighlight>
In this case, variables in files <tt>path/to/file1.nas</tt> and <tt>path/to/file2.nas</tt> can be used in the Nasal console as
  moduleA.varName;
Variables in <tt>path/to/file3.nas</tt> can be accessed as
  moduleB.varName;
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.
'''''More information can be found at [[Namespaces and Methods]].'''''


== Storage: property tree vs. Nasal ==
== Storage: property tree vs. Nasal ==

Navigation menu