• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

MSFS20 setInterval( ) within MSFS Update Section

Messages
159
Country
us-colorado
I cannot get the Javascript setInterval() function to work within a MSFS update section for an HTML gauge. No matter what interval I use (here 2 sec), the TEMP_TEST variable below increments at the same (very fast) rate.
Is there some limitation in using setInterval() within a MSFS update section, for example, maybe something to do with the update section rate vs the setInterval repeat rate (maybe the setInterval rate has to be faster then the Update section rate)?
Thx,
Al

Code:
          setInterval(()=> {this.TEMP_TEST++}, 2000);
          SimVar.SetSimVarValue("L:TEMP_TEST_VAL", "NUMBER", this.TEMP_TEST);    //This line just for display purposes in DEV mode
 
Last edited:
The setInterval() function is basically a repeditive or looping function, and as I was thinking about this it occurred to me that I don't think I've ever seen a typical loop operation, like a do -while or for loop, in any of the sim Javascript code. Does the nature of the way the sim operates preclude such loops in HTML gauges?
Thx,
Al
 
Well, I looked at the syntax again and the basic form for setInterval and the arrow function are:
-- setInterval(func, delay)
-- ( ) =>
If I remove the curly braces above, it does not seem to make any difference in the result since it is a single line arrow function. A multiline arrow function requires the curly braces, however.
Thanks,
Al
 
I wonder if the problem could be related to the setInterval delay time being greater than the Update section repeat time. For example, if the update section repeats every 100ms or so, what happens if the interval delay is 1000ms? Does the setInterval function get reset and "start over" (increment once) every 100ms so the 1000ms delay never happens? Said another way, I wonder if the count up rate I see is essentially the Update section repeat rate?
Thx,
Al
 
Last edited:
I suggest not including JS async timers in your game code - IMHO it's just asking for trouble conflicting with CoherentGT owning the 'outermost loop' of the high-speed Update handling down the chain of BaseInstrument subclasses.

Far safer will be to use the already-built-in Update callback support and simply check the time. Safe is to use either the various MSFS simvars (I recommend SIMULATION TIME) or in an unusual situation where you believe real-world time is more important than time inside the game, you can use JS Date() values. I have to say where I've seen the latter done, this has always been a rookie error from someone unfamiliar with issues that commonly arise in game programming. Someone in Asobo has made a really amateur error halfway down the Instrument code stack, passing an 'update delta time' value that is calculated by subtracting JS Dates, so that bears no relevance AT ALL to the timestep in the simulation defining the time gap between simvar values that are being passed in the same call.
 
Back
Top