I’ve created a custom in game panel which is loading ok. I’m having trouble
however accessing simvars via the in game panel. I’m getting ReferenceError:
Can’t find variable: simvar error in the coherent debugger. This is the code
I’m using to load the HTML
Can anyone see where I am going wrong? It feels like I am not referencing
Simvar correctly but been scratching my head all day. This is the error from
the console.
UPDATE: Thank you to you all for posting suggestions. This is what has
been tried so far and a possible solution by RoscoHead
Use console to check can read simvars - works
Try to add an addEventListener to wait until all js loaded - Doesn’t work (listener runs but simvar doesn’t work, tried in a connectedCallback and outside the class.)
Checked loading order of .js files as per the Asobo panels, this mirrors those.
Putting the simvar code into a window.setInterval waiting for 5secs works
There must be something that simvar.GetSimVarValue relies upon that isn’t
loading/initialising’ (for at the most 5secs) after the flight has loaded.
I’ve tried putting the code into onFlightStart() but this does not run at all.
Is there a list of functions available to the HTMLElement and when they run?
Does anyone have any insight into the timeline where the panel loads into the
sim? I thought it only loads when you click the icon? (see @RoscoHead’s issue
with trying to preload) It seems like waiting a few seconds then opening the
panel also doesn’t work so there is some loading weirdness going on here. If
anyone is interested this is a link to the panel code in its entirety in a
.zip. <https://yachtmanagercouk- my.sharepoint.com/:u:/g/personal/matt_yachtmanager_co_uk/EWnl1akTrmBFmHwj3IfwaxcBccFXbqHj6UR-
XdCFwQlGdw?e=DGa7Sb>
Sadly not getting very far with getting this working. I’ve checked and double
checked the code behind the custom panel, recompiled the spb etc. The panel
itself loads correctly but I can’t seem to be able to access any simvar. I
must be missing something in the panel html or javascript but really can’t see
where. This is the error i’m getting.
In the console, and that should give you your lat back. My guess is that in
this case above, the BonanzaElement HTMLElement is actually mounted to the DOM
before the script elements are (or something like that), and thus the JS is
not yet fully loaded when you get to connectedCallback. You may need to add an
event listener to something like DOMContentLoaded to ensure all the JS is
loaded before trying to set up your update cycle. -Matt
Hi @N6722C, thank you. Sadly this doesn’t work. I feel I am missing something
obvious, I’ve tried to look at loading order, and looked at the html/js
against the existing panel code.
I don’t currently have access to my PC to check, but I remember I was calling
GetSimVarValue in a loop, and it would get this error the first couple of
times through the loop. I couldn’t get rid of it, so just programmed to ignore
any results until it stops getting the error. I recall I had the same issue
with global vars like Sim rate and used the same workaround.
@RoscoHead, thank you! So success, if you add the code into a timer it
supplies the simvar.
1. var timerMilSecs = 5000;
2. var timer = window.setInterval(runme, timerMilSecs);
3. function runme() {
4. console.log(SimVar.GetSimVarValue("PLANE LATITUDE", "degree latitude"));
5. }
Could this be a bug??? My understanding of
1. addEventListener('load'...
Is that this fires once everything has loaded, js etc. There is something else
deeper in the sim that is not initialising or allowing us to read simvars
until a few seconds into the loading of the flight. It looks like we can’t use
OnFLightStart(). I wonder if there is another function other than
connectedCallback that we can use?
Hm, from my experience I thought connectedCallback should be late enough. But
there indeed seems to be a timing issue in your case. Possible that the flow
is different outside of BaseInstrument.
Hello, Calling SimVar in the connectedCallback is too early and it might not
have been loaded yet. Also, a good way to know it SimVar is loaded is to use
SimVar.IsReady()