• 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.

Updating single variable in a structure

Messages
15
Country
us-washington
Hi,

Forgive me if this has been asked before: What is the best (meaning most efficient such that it costs least amount of frames) way to update a single variable in a stuct of variables? I tried looking into tagged variables, but since I will be reading and potentially setting some of the variables in the struct often, I understand that tagged variables are not the way to go.

So, that leaves me with an option that is to keep track of the last updated struct and only setting the diffs of the struct members whereafter I can update the whole struct.

Any ideas?

Thanks,
Boaz Lev
 
If you want to set a *SINGLE* simulation variable, you can try doing this:



1) Define a DEFINITION_ID for update *ONLY* the plane's latitude:


Code:
SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_PLANE_LATITUDE, "Plane Latitude", "degrees");


NOTE: Notice that i'm definiting a FLOAT64 variable for the plane's latitude definition as FLOAT64 is the *DEFAULT* data type



2) Now, when you are ready to update *ONLY* the plane's latitude:


Code:
// Declare my variable
double plane_lat = 9.3847572; // DOUBLE = FLOAT64

// Update *ONLY* the latitude on USER's AIRCRAFT
SimConnect_SetDataOnSimObject(hSimConnect, DEFINITION_PLANE_LATITUDE, SIMCONNECT_OBJECT_ID_USER, 0, sizeof(double), &plane_lat);


NOTE: Notice that im using "double" because we defined the "DEFINITION_PLANE_LATITUDE" to be a FLOAT64 variable in other words a "DOUBLE", that's why im setting --> "sizeof(double), &plane_lat"


For update more *INDIVIDUAL* variables, you will need to define more DEFINITION_IDs, and so on...


Hope that helps,



Manuel
 
Hi Manuel,

I thought of that approach, but I am wondering if splitting out logically related variables into several definitions in the long run is the best approach for performance. Doesn't that mean that FS(X) will have to call me back more frequently -- one for each define -- as opposed to one time for the whole master define that holds all the variables I am interested in?

Thanks for responding :)
 
You could create one master struct and use it to have FS send you updates and then create several smaller structs and use them to send modifications back to FS.

Daniel
 
Back
Top