I need a way to ACTIVE PAUSE the sim from a JS or an XML, but the only PAUSE feature I find pauses all the sim and I am unable to unpause it from the top bar of the sim
Thanks!
I need a way to ACTIVE PAUSE the sim from a JS or an XML, but the only PAUSE feature I find pauses all the sim and I am unable to unpause it from the top bar of the sim
Thanks!
Hello @Boeing738
Have a look at the TOOLBAR_SET_ACTIVE_PAUSE call from the JS_LISTENER_TOOLBAR_PANELS.
This is what’s used by the default active pause button in the in-game panel toolbar.
Regards,
Sylvain
Hi Sylvain,
I am trying this but its not doing anything,
this.toolbarListener = RegisterViewListener('JS_LISTENER_TOOLBAR_PANELS');
...
Coherent.trigger('SetActivePauseEnabled', 1);
Any example code that you might have?
Thanks!
The Register call is correct but try this call instead:
Coherent.call("TOOLBAR_SET_ACTIVE_PAUSE",true)
Regards,
Sylvain
I am trying something like that but I get this error:
[Error] Unhandled Promise Rejection: NoSuchMethod: TOOLBAR_SET_ACTIVE_PAUSE not bound. Call engine.trigger instead of engine.call if you do not bind nor need the result.
(anonymous function)
rejectPromise
_OnError (coherent.js:433)
The I try this and does not work either:
try { getTopEngine().trigger('TOOLBAR_SET_ACTIVE_PAUSE', true); } catch …
PD: I am trying that in JS, do you happen to have a complete code with like a click button to test or something?
You can check here, this approach should work: fix(misc): replace msfs popup for TOD pause by Saschl · Pull Request #10656 · flybywiresim/aircraft · GitHub
Thank you so much! That was great help
With some AI I managed to have a button to toggle active pause
active-pause-button-guide.pdf (216.1 KB)
Example:
declare var RegisterViewListener: any;
declare var engine: any;
function getTopEngine(): any {
try {
return (window.top as any).engine ?? engine;
} catch {
return engine;
}
}
class ActivePauseController {
private listener: any = null;
private listenerReady = false;
private button: HTMLButtonElement;
constructor(button: HTMLButtonElement) {
this.button = button;
this.registerListener();
this.button.addEventListener(‘click’, () => this.toggle());
this.updateLabel();
setInterval(() => this.updateLabel(), 500);
}
private registerListener(): void {
if (this.listener) {
return;
}
this.listener = RegisterViewListener(‘JS_LISTENER_TOOLBAR_PANELS’, () => {
this.listenerReady = true;
});
}
private toggle(): void {
const isPaused = !!(SimVar.GetSimVarValue(‘A:IS IN ACTIVE PAUSE’, ‘Bool’) as
number);
const nextState = !isPaused;
try {
if (this.listenerReady && this.listener && typeof this.listener.call ===
‘function’) {
this.listener.call(‘TOOLBAR_SET_ACTIVE_PAUSE’, nextState);
} else {
getTopEngine().trigger(‘TOOLBAR_SET_ACTIVE_PAUSE’, nextState);
}
} catch {
getTopEngine().trigger(‘TOOLBAR_SET_ACTIVE_PAUSE’, nextState);
}
this.updateLabel();
}
private updateLabel(): void {
const isPaused = !!(SimVar.GetSimVarValue('A:IS IN ACTIVE PAUSE', 'Bool') as
number);
this.button.textContent = isPaused ? ‘Resume Sim’ : ‘Pause Sim’;
}
}