Using a Nasal file with a joystick: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
{{WIP}}
== Background ==
Sometimes the code for a button is quite complicated. Not only does it make your xml file larger and more difficult to go through, but writing the code in a dedicated Nasal file cane be a lot easier. There are things which are just easier that way. You may also have come across an example in the forums which you want to use, and you don't know how to do it.
Whatever your reason for using a Nasal file, this is how to implement it.
==  Getting Started ==
You are going to put your Nasal file in the same folder as your joystick's xml file. You need to choose a suitable name for the file. If your joystick is a KungFu ABC123 you could safely name the file abc123.nas. If, however, you have a Saitek yoke, you don't want to name the file yoke.nas, because in the Saitek folder is a Pro Flight Yoke and a Cessna Yoke, so you want to be more specific. Call the file cessnayoke.nas or proflightyoke.nas'
The name you choose is visible ''everywhere'' in FG, so make sure you choose something unique.
Notice that there are no capital letters.
So open up your favourite text-editor, create a new file, and save it in your joystick's folder with the chosen filename. Don't forget that the extension must be .nas, and make sure your editor doesn't make it .nas.txt.
==  Changes to your joystick's xml file  ==
'''Save a copy of your xml file in a safe place, one that you will remember.'''
For the sake of this exercise we will assume that you have a KungFu ABC123 joystick. So your nasal file is abc123.nas.
Open the xml file.
At the top, just after all the <name> entries, add this:
  <nasal>
    <script>
      if (!contains(globals, "abc123")) {
        io.load_nasal(getprop("/sim/fg-root") ~ "/Input/Joysticks/KungFu/abc123.nas");
      }
 
      abc123.initABC123();
    </script>
  </nasal>




{{WIP}}
[[Category:Howto]]
[[Category:Howto]]
[[Category:Hardware]]
[[Category:Hardware]]

Revision as of 06:22, 3 February 2013

WIP.png Work in progress
This article or section will be worked on in the upcoming hours or days.
See history for the latest developments.

Background

Sometimes the code for a button is quite complicated. Not only does it make your xml file larger and more difficult to go through, but writing the code in a dedicated Nasal file cane be a lot easier. There are things which are just easier that way. You may also have come across an example in the forums which you want to use, and you don't know how to do it.

Whatever your reason for using a Nasal file, this is how to implement it.


Getting Started

You are going to put your Nasal file in the same folder as your joystick's xml file. You need to choose a suitable name for the file. If your joystick is a KungFu ABC123 you could safely name the file abc123.nas. If, however, you have a Saitek yoke, you don't want to name the file yoke.nas, because in the Saitek folder is a Pro Flight Yoke and a Cessna Yoke, so you want to be more specific. Call the file cessnayoke.nas or proflightyoke.nas'

The name you choose is visible everywhere in FG, so make sure you choose something unique.

Notice that there are no capital letters.

So open up your favourite text-editor, create a new file, and save it in your joystick's folder with the chosen filename. Don't forget that the extension must be .nas, and make sure your editor doesn't make it .nas.txt.


Changes to your joystick's xml file

Save a copy of your xml file in a safe place, one that you will remember.

For the sake of this exercise we will assume that you have a KungFu ABC123 joystick. So your nasal file is abc123.nas.

Open the xml file.

At the top, just after all the <name> entries, add this:

 <nasal>
   <script>
     if (!contains(globals, "abc123")) {
       io.load_nasal(getprop("/sim/fg-root") ~ "/Input/Joysticks/KungFu/abc123.nas");
     }
 
     abc123.initABC123();
   </script>
 </nasal>