Lagaffe
Resource contributor
- Messages
- 989
- Country

Good evening,
Reading a lot of B-21-soaring 's javascript (present in many freeware) I was able to write a js that allows me to manage via a 3D button on the VC the extension/closure of a cargo door on an aircraft.
The animation of this opening is managed by the variable A:FLAPS HANDLE PERCENT.
I also wanted this door to be able to open in MSFS External view via two keys on the keyboard that are mapped to the RETRACT FLAPS (event FLAPS_UP) and EXTEND FLAPS (event FLAPS_DOWN).
There is also an visual effect displayed wihen this door is opening via an L;var PBV_TankDumping (boolean).
The code has already been written for the model/aircraft.xml and works very well when the door is controlled via the VC and a click on the 3D button.
Is it possible in the javascript to read a variable like A:FLAPS HANDLE PERCENT (it varies from 0 to 100 for a press on FLAPS DOWN) and to set the L:Var to display the effect?
I have read this afternoon a lot of topic on this subject without finding a reale solution to my problem.
One test of mine:
In DEV Mod - Windows - Behaviors - LocalVariables, I cann't see PBV_SwitchTank changing when KEY is press as PBV_TankDumping which does not want to be modificated.
[EDIT] I just modify my post to be more exhaustive, with the time management and the update cycle used.
Reading a lot of B-21-soaring 's javascript (present in many freeware) I was able to write a js that allows me to manage via a 3D button on the VC the extension/closure of a cargo door on an aircraft.
The animation of this opening is managed by the variable A:FLAPS HANDLE PERCENT.
I also wanted this door to be able to open in MSFS External view via two keys on the keyboard that are mapped to the RETRACT FLAPS (event FLAPS_UP) and EXTEND FLAPS (event FLAPS_DOWN).
There is also an visual effect displayed wihen this door is opening via an L;var PBV_TankDumping (boolean).
The code has already been written for the model/aircraft.xml and works very well when the door is controlled via the VC and a click on the 3D button.
Is it possible in the javascript to read a variable like A:FLAPS HANDLE PERCENT (it varies from 0 to 100 for a press on FLAPS DOWN) and to set the L:Var to display the effect?
I have read this afternoon a lot of topic on this subject without finding a reale solution to my problem.
One test of mine:
Code:
update_keypress() {
this.FLAPS = SimVar.GetSimVarValue("A:FLAPS HANDLE PERCENT","percent");
if (this.FLAPS != 0) {
this.tank_open = true;
} else {
this.tank_open = false;
}
}
Code:
tank_system_update()
this.tank_system_init(); // initialization of local variables tank_open, this.tank_dumping, this.witch_tank
let time_delta = this.TIME - this.prev_time;
if (time_delta < 0 || time_delta > 5) {
this.prev_time = this.TIME;
return;
}
if (time_delta_s < 1) {
return;
}
this.prev_time = this.TIME;
let tank_changed = false;
if (this.tank_left > 0 && this.tank_right > 0 && this.switch_tank) {
tank_changed = true;
if (!this.tank_dumping && !this.ON_GROUND) {
this.tank_dumping = true;
SimVar.SetSimVarValue("L:pBV_TankDumping","number",1);
}
this.tank_left = Math.max(this.tank_left - time_delta * this.DumpRate , 0);
this.tank_right = Math.max(this.tank_right - time_delta * this.DumpRate , 0);
SimVar.SetSimVarValue("A:pAYLOAD STATION WEIGHT:4","kilograms", this.tank_right);
SimVar.SetSimVarValue("A:pAYLOAD STATION WEIGHT:3","kilograms", this.tank_left);
}
if (!tank_changed && this.tank_dumping) {
SimVar.SetSimVarValue("L:pBV_TankDumping","number",0);
this.tank_dumping = false;
}
if (this.tank_open) {
this.switch_tank = ! this.switch_tank;
SimVar.SetSimVarValue("L:pBV_SwitchTank","number", this.switch_tank ? 100 : 0); // for the 3D button in the VC
}
if (!this.tank_open) {
this.switch_tank = ! this.switch_tank;
SimVar.SetSimVarValue("L:pBV_SwitchTank","number", this.switch_tank ? 100 : 0);
}
}
[EDIT] I just modify my post to be more exhaustive, with the time management and the update cycle used.
Last edited:

