Anteworld - Outerra Game > JavaScript development

EvantHandlers

(1/2) > >>

SteelRat:
Hi cameni!

I really liked this event handler

--- Code: ---this.register_axis()
--- End code ---
It provides opportunities for creativity, and I once again have to use it instead

--- Code: ---this.register_event()
--- End code ---

That's why, let's say there is a handler

--- Code: ---this.register_axis("car/CARsim/all_wheels", {minval:0, maxval:1, center:0, vel:1000, acc:1000}, function(v) {
      if (Math.round(this.speed()) == 0) this.tm.allWheels = v;
}, 0);
--- End code ---

Let the vehicle travels during a call event, it is natural to the user action will not be taken by itself is not terrible)

BUT !!!
Counter "v" has changed its meaning, that in the future will cause not the correct effect.

And use this handler like)

SteelRat:
Hi cameni!

How to make a "reset" the two axes of one button?
Since working with only one axle.


--- Code: ---this.register_axis("car/CARsim/view_cabin_cam_move", {minval:0, maxval:0.45, center:0, vel:2, acc:2}, function(v) {
   this.player.moveCamPos.y = v;
   this.player.moveCam = 1;
}, 0);

this.register_axis("car/CARsim/view_cabin_cam_strafe", {minval:-0.3, maxval:0.3, center:0, vel:2, acc:2}, function(v) {
   this.player.moveCamPos.x = v;
   this.player.moveCam = 1;
}, 0);

--- End code ---


--- Code: ---{
    "name": "view_cabin_cam_move",

    "comment": "View: Move the camera forward/backward",

    "important": true,

    "bindings": [
         {

            "event_name": "Num8",
            "mode": "toggle+"
         },
         {

            "event_name": "Num2",
            "mode": "toggle-"

         },
         {
            "event_name": "Num5",

            "mode": "reset"
         }

     ]

},
{

     "name": "view_cabin_cam_strafe",

     "comment": "View: Move the camera left/right",
     "important": true,
     "bindings": [

         {

             "event_name": "Num4",

             "mode": "toggle-"

         },

         {
             "event_name": "Num6",

             "mode": "toggle+"

         },

         {

             "event_name": "Num5",
             "mode": "reset"
         }

     ]

}

--- End code ---

cameni:

--- Quote from: SteelRat on September 30, 2015, 11:49:32 am ---BUT !!!
Counter "v" has changed its meaning, that in the future will cause not the correct effect.

--- End quote ---

You mean it changed meaning between register_event and register_axis? I don't know what you mean by "in the future will cause not the correct effect".


--- Quote ---How to make a "reset" the two axes of one button?
--- End quote ---

You mean how to use one button to reset two separate axes at once? It's not possible with a simple binding in two actions, you would have to create a third action that you'd bind as register_event and reset both values there. But ideally that needs ability to access the other actions to reset or set their values, and that's not currently possible ...

SteelRat:

--- Quote ---You mean it changed meaning between register_event and register_axis? I don't know what you mean by "in the future will cause not the correct effect".

--- End quote ---

RU
Я не имел ввиду каких либо глобальных проблем, я рассуждаю о пользовательском уровне.

Например я создаю подобный обработчик события

--- Code: ---this.register_axis("car/CARsim/all_wheels", {minval:0, maxval:1, center:0, vel:1000, acc:1000}, function(v) {
      if (Math.round(this.speed()) == 0) this.tm.allWheels = v;
}, 0);

--- End code ---
В этом обработчике поставлено конкретное условие, при соблюдении которого изменения вступят в силу.
Начальное значение параметра V = 0.

Теперь представим такую ситуацию, пользователь во время движения автомобиля решил активировать ведущими все оси, естественно код в обработчике этого не позволит сделать, и не последует ни какого эффекта, автомобиль должен остановиться, что бы изменения вступили в силу. Само по себе это не проблема.
А проблема в том, что при следующем вызове этого события значение переданного в обработчик события параметра V будет равно 0, а не 1, так как предыдущий вызов хоть и не внёс ни каких изменений в логику автомобиля, но зато изменил значение V = 1.

Именно это я и имел ввиду.

И сначала я решил именно с этим обработчиком события связать взаимодействие с коробкой передач. Но когда дело дошло до автоматической коробки я понял, что использовать этот обработчик мне не получится, именно из за описанного выше эффекта.
И как раз из за того, чтобы переключить передачу на автомобиле с коробкой автомат, автомобиль не должен двигаться, и это условие пользователем может быть не соблюдено, в результате, начав играться с переключением передач на ходу, пользователь сведёт с ума логику). А у меня нет инструмента блокировать бестолковые выходки пользователя. Потому что у меня нет возможности дать указание не менять значение параметра V.

Может имеет смысл возвращать из функции обработчика результат обработки события TRUE или FALSE, и по результату уже принимать решение изменять значение параметра V, или оставить предыдущее значение.
Как здесь

--- Code: ---function switch_seat(cam)
{
  if(cam===0)       //driver
    this.set_fps_camera_pos({x:-0.8,y:3.4,z:2.3});
  else if(cam===1)  //right seat
    this.set_fps_camera_pos({x:+0.8,y:3.4,z:2.3});
  else if(cam===2)  //wheel
    this.set_fps_camera_pos({x:-1.8,y:2.0,z:0.6});
  else
    return false;
  return true;
}

--- End code ---

SteelRat:

--- Quote ---You mean how to use one button to reset two separate axes at once? It's not possible with a simple binding in two actions, you would have to create a third action that you'd bind as register_event and reset both values there. But ideally that needs ability to access the other actions to reset or set their values, and that's not currently possible ...
--- End quote ---

If I understand correctly, no.
OK. Thank.

Navigation

[0] Message Index

[#] Next page

Go to full version