Howto:Write simple scripts in Nasal: Difference between revisions

Jump to navigation Jump to search
m
Robot: Cosmetic changes
m (Small adjustments)
m (Robot: Cosmetic changes)
Line 7: Line 7:
Such a script should ideally be very generic so that it can be reused easily; but the script here is deliberately kept as simple as possible.
Such a script should ideally be very generic so that it can be reused easily; but the script here is deliberately kept as simple as possible.


===Creating the nasal file===
=== Creating the nasal file ===
As with many other things in FG, nasal functions can live in many different places. Here, however, we're going to create a "Systems" directory under the Main fokker50 directory. Later, other files might be added to this directory; an electrical system, functions to control other cockpit indicators, etc.
As with many other things in FG, nasal functions can live in many different places. Here, however, we're going to create a "Systems" directory under the Main fokker50 directory. Later, other files might be added to this directory; an electrical system, functions to control other cockpit indicators, etc.


Line 38: Line 38:
<pre>}</pre>
<pre>}</pre>


===Including the nasal file in the -set file===
=== Including the nasal file in the -set file ===
To make sure our aircraft "knows" about this nasal file, we will need to add a section to the main aircraft -set.xml (in this case, fokker50-set.xml of course).
To make sure our aircraft "knows" about this nasal file, we will need to add a section to the main aircraft -set.xml (in this case, fokker50-set.xml of course).


Line 58: Line 58:
<pre>fokker50.convertTemp();</pre> and press execute. (The "fokker50" part comes from the entry we made in the -set xml file)
<pre>fokker50.convertTemp();</pre> and press execute. (The "fokker50" part comes from the entry we made in the -set xml file)


[[Image:nasal_console.jpg]]
[[File:nasal_console.jpg]]


You can see in the property browser (file/browse internal properties) that we now have a new egt property for the first engine (/engines/engine), with the value in degC - success!
You can see in the property browser (file/browse internal properties) that we now have a new egt property for the first engine (/engines/engine), with the value in degC - success!
Line 76: Line 76:
This listens for the fdm-initialized property to be set (this will happen when the sim has started up), and starts our convertTemp function when that happens.
This listens for the fdm-initialized property to be set (this will happen when the sim has started up), and starts our convertTemp function when that happens.


===Finishing up===
=== Finishing up ===
As an "exercise for the reader" (I always hate those!) you should make the script also convert the temperature values for the second engine.
As an "exercise for the reader" (I always hate those!) you should make the script also convert the temperature values for the second engine.


Navigation menu