• 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 Beginner needs help with data type

Messages
3
Country
france
Hello,

I'm starting out with programming using Simconnect and VB.net.
What I started doing is working.
But when I write this line of code:

Code:
Structure Struct1
    Public Speed As Double
End Structure

MSFSobj.SimObjet.AddToDataDefinition(StructDefinitions.Struct1, "Ground Velocity", "knots", Microsoft.FlightSimulator.SimConnect.SIMCONNECT_DATATYPE.FLOAT64, 0, 0)

I don't know why "knots" is of type "Float64".

Regarding the Simvar "GROUND VELOCITY", the SDK documentation only indicates the description and the unit.

How do you know which VB data type corresponds to which Simconnect Unit?
 
Hi Phil,

I don't know why "knots" is of type "Float64".

The data type you specify needs to be able to contain the type of value you expect or want. For numeric data types (basically everything except strings), there's no hard rule as to which SimConnect type to use, but it must match the bit size you specify as your container variable type. So in your example you use a Double size variable for Speed, which is 64 bits and therefore the SimConnect FLOAT64 data type is the correct match (both are same size and represented the same way in the bit layout).

However if you don't need 64-bit precision for that value (which you probably don't), then it would be just as valid to make Speed a Single type (32-bit floating point) and use FLOAT32 SimConnect data type.

Or if you don't care about fractions at all, you could make Speed be an Int32 type and use SIMCONNECT_DATATYPE_INT32 type.

Similar for integer type sim values or enums or booleans. You could just specify them all as Doubles (both in your storage and in the AddToDataDefinition() call), but that could waste storage space and network traffic (data sizes) and possibly slow down math or comparison operations. Instead you could use the smaller INT32 (integer) type.

Arguably, the only values from the sim that really need double precision are Lat/Lon.

Unrelated, but keep in mind you don't need a structure if you just want a single variable -- you can use/register a single variable directly w/out needing a struct wrapper. Unfortunately the official documentation doesn't show this.

Hope that helps,
-Max
 
Last edited:
Two points:

1 - Not all data types work correctly with all variables, dunno why. FLOAT64 is the most common and typically works for all sim variables.
2 - FLOAT64 is a Double, which is a floating-point value (fractional parts are supported).
 
And if FLOAT64 doesn't work (e.g. ON GROUND) then FLOAT32 does work. A loooong time ago I picked up the information that all FS internal variables are doubles (most likely from one of the ACES team but I'm no longer able to swear to that). A lot of the FS stuff has carried forward into MSFS202x as what they call 'legacy' and SimConnect is pretty much all 'legacy'.
 
Back
Top