Input device: Difference between revisions

Jump to navigation Jump to search
1,551 bytes removed ,  19 October 2009
Line 368: Line 368:
These characters will cause problems even if simply included in comments or within scripts.
These characters will cause problems even if simply included in comments or within scripts.


===Useful hints for scripts===
===Saitek===
Some particularly useful ideas for programming scripts within joystick XML files:
Some particularly useful ideas for programming scripts within joystick XML files:
* getprop and setprop can be used for getting & setting properties from the internal properties tree:
* getprop and setprop can be used for getting & setting properties from the internal properties tree:
Line 381: Line 381:


  print("Just", " a ", "test");
  print("Just", " a ", "test");
* 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:
gui.popupTip("Parking Brake ON");
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:
gui.popupTip(sprintf("Elevator trim: %d", 100 * getprop("/controls/flight/elevator-trim")));
Or
thv = getprop("/controls/engines/engine[0]/mixture");
gui.popupTip("Thrust vector " ~ int(thv * 120 - 20));
* You can just start using variables, ie,
x = 10;
But [http://wiki.flightgear.org/index.php/Nasal_scripting_language#Variables for various reasons] it is generally better to declare variables with the "var" statement:
var x = 10;
Note that "var" 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.
* You can include a section of script that runs on startup to initialize variables, create functions, etc.  Example:
<PropertyList>
  <name type="string">My joystick name</name>
  <name type="string">My joystick name #2</name>
  <nasal>
    <script>
        #initialize variables
        f1 = f2 = 0;
        left_brake = right_brake = 0;
        # create a function to be used with all buttons
        getmod = func { getprop("/input/joysticks/js[0]/t-flight-hotas-x-modifier" ) }
    </script>
  </nasal>


==Resource==
==Resource==
* [http://www.flightgear.org/Docs/getstart/getstartch3.html#x8-360003.6 The FlightGear Manual]
* [http://www.flightgear.org/Docs/getstart/getstartch3.html#x8-360003.6 The FlightGear Manual]
5,775

edits

Navigation menu