Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Download Outerra Tech Demo. Unofficial Outerra Discord server, MicroProse Discord server for OWS.

Author Topic: Extended controls  (Read 4546 times)

zzz

  • Sr. Member
  • ****
  • Posts: 266
  • newbie
Extended controls
« on: September 19, 2015, 07:37:47 pm »

Having a bit of trouble with extended keys. I can only get them to toggle. Has anyone got them so that a variable = 1 on the keypress and resets to 0 when the key is released?

For example, converting this deprecated code:

Code: [Select]
//handle extra actions
function action(k,v,dt)
{

  switch(k){
 
// Pitch Down command
case AAuxb1:

          if (v == 1) {
               movePitchDown = 1;
}

if (v == 0) {
movePitchDown = 0;
}

break;
}

I tried

Code: [Select]
this.register_event("car/controls/power", function() {
movePitchDown = 1;             
if (movePitchDown == 1) {
          movePitchDown = 0;
}
}
});

and

Code: [Select]
this.register_switch("car/controls/power", function(v) {
if (v==1) {
movePitchDown = 1;             
} else {
movePitchDown = 0;
}
});

and several variations.
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Extended controls
« Reply #1 on: September 20, 2015, 02:21:55 am »

register_event only invokes on key press.
register_switch is a toggle.

You should use register_axis like this:
Code: [Select]
this.register_axis("car/controls/power", {minval:0, center:1000, vel:1000, acc:1000}, function(v){ movePitchDown = v })

Vel defines the speed at which the value changes during key press, you could also use Number.POSITIVE_INFINITY there instead of 1000 to guarantee instant switches, but in reality nothing is instant so you should have there a number that says how fast it switches. A value of 1000 means that it changes from 0 to 1 in 1/1000 sec.

Center tells how fast the value goes back to 0 upon button release. If it's zero, the value stays where it was and you need a second key binding with negative mode that can push it back. Also, if you only have one key bound to such an action, it automatically becomes a toggle.
Logged