Writing Joystick Code: Part 2: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
No edit summary
mNo edit summary
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{JoystickScripting Navigation}}
== Code snippets  ==
== Code snippets  ==


Line 26: Line 28:
Some Actions will have code for use with repeatable and non-repeatable buttons. Sometimes it is not wise to use the wrong type for a certain action. And sometimes you must use the correct type for an action - using a non-repeating button for Zoom is a bad idea, the user will have to constantly keep triggering the button to reach the zoom level he requires. Using a repeatable button is possible for something like gearDown, as long as the use knows to just use a brief push, but it is a bad idea.
Some Actions will have code for use with repeatable and non-repeatable buttons. Sometimes it is not wise to use the wrong type for a certain action. And sometimes you must use the correct type for an action - using a non-repeating button for Zoom is a bad idea, the user will have to constantly keep triggering the button to reach the zoom level he requires. Using a repeatable button is possible for something like gearDown, as long as the use knows to just use a brief push, but it is a bad idea.


Notice that some commands have a +1 or a -1 in brackets to specify the direction of the action, and a 0 to say stop doing that. The 0 version will of course be in the <mod-ip> section.
Notice that some commands have a +1 or a -1 in brackets to specify the direction of the action, and a 0 to say stop doing that. The 0 version will of course be in the <mod-up> section.


If the action is upside-down for you, swap the + and - signs.
If the action is upside-down for you, swap the + and - signs.
Line 114: Line 116:
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
  Make mixture richer R C
  Make mixture richer R C
     <![CDATA[
     controls.adjMixture(0.05)
      if(getprop("controls/engines/engine/mixture") < 1 ) {
        setprop("controls/engines/engine/mixture", getprop ("controls/engines/engine/mixture") + 0.05)
      }
    ]]>
   
   
  Make mixture leaner R C
  Make mixture leaner R C
    <![CDATA[
    controls.adjMixture(-0.05)
        if(getprop("controls/engines/engine/mixture") > 0 ) {
          setprop("controls/engines/engine/mixture", getprop("controls/engines/engine/mixture") - 0.05)
        }
    ]]>
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
  Start all engines R
  Start all engines R
Line 160: Line 154:
   
   
   Select previous weapon NR
   Select previous weapon NR
     controls. weaponSelect(-1)
     controls.weaponSelect(-1)
   
   
   Select next weapon NR
   Select next weapon NR
     controls. weaponSelect(-1)
     controls.weaponSelect(-1)
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
  Toggle all lights on/off NR
  Toggle all lights on/off NR
Line 222: Line 216:
as part of being a programmer is making your code legible for others.
as part of being a programmer is making your code legible for others.


-----------------------------------------------------------------------------
Go back to [[Writing Joystick Code: Part 1]].
Go forward to [[Writing Joystick Code: Part 3]]




Line 233: Line 221:




Any complaints/suggestions/questions/kudos can be posted [http://flightgear.org/forums/viewtopic.php?f=24&t=17892 here].
Any complaints/suggestions/questions/kudos can be posted [http://forum.flightgear.org/viewtopic.php?f=24&t=17892 here].
 


== Related content ==
* [[Joystick xml library]]


[[Category:Hardware]]
[[Category:Hardware]]
6

edits

Navigation menu