Es/Joystick: Difference between revisions

Jump to navigation Jump to search
Line 306: Line 306:
* All Nasal code shares a common namespace, so it's possible to set a variable in one nasal binding, and to read it in another.
* All Nasal code shares a common namespace, so it's possible to set a variable in one nasal binding, and to read it in another.


===Useful hints for scripts===
===Pistas Útiles para scripts===
Some particularly useful ideas for programming scripts within joystick XML files:
Algunas ideas particulares útiles para programar scripts en archivos XML de palanca de mandos:
* getprop and setprop can be used for getting & setting properties from the internal properties tree:
* getprop y setprop pueden ser usados para obtener y seleccionar propiedades desde el arbol de propiedades internas:
  var brake = !getprop("/controls/gear/brake-parking");
  var brake = !getprop("/controls/gear/brake-parking");
  setprop("/controls/gear/brake-parking", brake);
  setprop("/controls/gear/brake-parking", brake);


* You can also make your own values on the property tree:
* Tambien puedes crear tus propios valores en el árbol de propiedades:
  setprop("/input/joysticks/js[0]/myjoystick-modifier", 1);
  setprop("/input/joysticks/js[0]/myjoystick-modifier", 1);
  var mod = getprop("/input/joysticks/js[0]/myjoystick-modifier");
  var mod = getprop("/input/joysticks/js[0]/myjoystick-modifier");


* You can print to terminal using the print function. This is very useful for debugging.
* Puedes imprimirlo en la terminal usando la función print. Esto es muy útil para la depuración de errores.


  print("Just", " a ", "test");
  print("Aquí", " va ", "el texto");


* You can display info in FlightGear via a popupThis is useful for giving the user feedback about changes that may not be obvious via the panel.  It can also be useful for debuggingExample:
* Puedes sacar por pantalla información en FlightGear a traves de pantalla emergenteEsto es muy útil para dar al usuario respuesta sobre cambios que no sean obvios a traves del panel.  Esto tambien puede ser útil para la depuración de erroresEjemplo:


  gui.popupTip("Parking Brake ON");
  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:
Los argumentos para gui.popupTip deben ser cadenas de caracteres, por tanto si quieres sacar por pantalla otros tipos de variables tendran que ser formateadas con algo como sprintf:


  gui.popupTip(sprintf("Elevator trim: %d", 100 * getprop("/controls/flight/elevator-trim")));
  gui.popupTip(sprintf("Elevator trim: %d", 100 * getprop("/controls/flight/elevator-trim")));


Or
O


  thv = getprop("/controls/engines/engine[0]/mixture");
  thv = getprop("/controls/engines/engine[0]/mixture");
  gui.popupTip("Thrust vector " ~ int(thv * 120 - 20));
  gui.popupTip("Thrust vector " ~ int(thv * 120 - 20));


* You can just start using variables, ie,  
* Puedes inicializar el uso de variables, Ej,  
  x = 10;
  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:
Pero[http://wiki.flightgear.org/index.php/Nasal_scripting_language#Variables for various reasons] generalmente es mejor declarar las variables con la sentencia "var":
  var x = 10;
  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.
Debes saber que "var" crea variables en el ámbito local, la cual causaria problemas si estas intentando usar una variable globalmente entre todos tus archivos de interconexión de palanca de mando XML.


* You can include a section of script that runs on startup to initialize variables, create functions, etc.  Example:
* Puedes incluir una sección de código que corra en el comienzo para inicializar variables, crear funciones, etc.  Ejemplo:
  <PropertyList>
  <PropertyList>
   <name type="string">My joystick name</name>
   <name type="string">My joystick name</name>
Line 347: Line 347:
   <nasal>
   <nasal>
     <script>
     <script>
         #initialize variables
         #initializar variables
         f1 = f2 = 0;
         f1 = f2 = 0;
         left_brake = right_brake = 0;
         left_brake = right_brake = 0;
         # create a function to be used with all buttons
         # crear una función para ser usada con todos los botones
         getmod = func { getprop("/input/joysticks/js[0]/t-flight-hotas-x-modifier" ) }
         getmod = func { getprop("/input/joysticks/js[0]/t-flight-hotas-x-modifier" ) }
     </script>
     </script>
5,810

edits

Navigation menu