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

Setting Multiple A:vars with one Simconnect call

Messages
65
Country
us-massachusetts
My apologies if this question has already been asked - I searched the forum and could not find it.

The FSX SDK gives the ability to use simconnect_setDataOnSimObject() to pass an array of variables. As an example of this, it shows setting several waypoints for an AI plane. My question is, is this possible with any other A:vars, or only AI waypoints? Specifically, I'd like to set all the payload weights in 1 call by passing in an array of doubles... All my experimentation suggests it is not possible with anything other than the "AI waypoints list". But perhaps I am doing something wrong. Has anyone ever been able to do this? and if so, how?

Thanks so much,
Farley
 
Farley,

I don't know how much this will help you, because I think that you are probably using C++, but I use Simconnect managed code (C++/CLI) to load fuel and stations.

I'll try to give you a few relevant snippets and maybe you can get an idea of something you overlooked. If by chance, this helps, but you would like to see more code, no problem.

In my Simconnect declarations, I have:
Code:
        enum class DEFINITIONS
        {
            Struct1,
            DATA_DEFINITION_CENTER_QUANTITY,
            DATA_DEFINITION_CENTER2_QUANTITY,
            DATA_DEFINITION_CENTER3_QUANTITY,
...more fuel tanks
            DATA_DEFINITION_STATION_WEIGHT1,
            DATA_DEFINITION_STATION_WEIGHT2,
            DATA_DEFINITION_STATION_WEIGHT3,
...more stations

Then, in my initialize data:
Fuel tanks add to data definition:
Code:
simconnect->AddToDataDefinition(DEFINITIONS::DATA_DEFINITION_CENTER_QUANTITY, "FUEL TANK CENTER QUANTITY", "Gallons", SIMCONNECT_DATATYPE::FLOAT64, 0, SimConnect::SIMCONNECT_UNUSED);
And so on...

Station weights add to data definition: NOTE PAYLOAD STATION WEIGHT: index is 1 number higher than actual station number.
Code:
simconnect->AddToDataDefinition(DEFINITIONS::DATA_DEFINITION_STATION_WEIGHT1, "PAYLOAD STATION WEIGHT:2", "Pounds", SIMCONNECT_DATATYPE::FLOAT64, 0, SimConnect::SIMCONNECT_UNUSED);
And so on...

Then, in my set data:
Load fuel SetDataOnSimObject:
Code:
simconnect->SetDataOnSimObject(DEFINITIONS::DATA_DEFINITION_CENTER2_QUANTITY, SimConnect::SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG::DEFAULT, center2);
etc., etc....

Load station SetDataOnSimObject:
Code:
simconnect->SetDataOnSimObject(DEFINITIONS::DATA_DEFINITION_STATION_WEIGHT2, SimConnect::SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG::DEFAULT, sta2Wt);
etc., etc....

I hope this gives you some idea for what you need to do.

This is from a flight planner/ aircraft loader that I made for a few specific planes. I haven't looked at the code for a long time and in trying to give you something useful, I might have left something out.

Good luck!

Edit: I suggest you post some code that you have tried and one of the C++ gurus can no doubt help you
 
Last edited:
So in your example you are using one SetDataOnSimObject() for EACH payload station, correct? My question was if it's possible to do it in 1, something like:

AddToDataDefinition(DEFINITIONS::DATA_DEFINITION_ALL_STATIONS, "PAYLOAD STATION WEIGHT", "Pounds", SIMCONNECT_DATATYPE::FLOAT64, 0, SimConnect::SIMCONNECT_UNUSED);

and then:

double payloads[64];

payloads[0] = 325.2;
payloads[1] = 2.0;
payloads[2] = etc. etc.

SetDataOnSimObject(DEFINITIONS::DATA_DEFINITION_ALL_STATIONS, objID, NULL, 64, sizeof(double), payloads);

Apologies for the sort of hybrid managed/native/pseudocode, but you get my point.

Until there is someone who knows otherwise, my current belief is that it is impossible, and the only variable which can be set this way is the "Waypoint List" from the SDK example. :(


Thanks for your help,
Farley
 
Yes you can. You use a single definition, and you do multiple AddToDataDefinitions with it. The order in which you add the sim vars to the datadefs is the order you must match in your struct or array. The sizeof value passed to the SetDataOnSimObject call must be the size of the struct or array.
 
Here is an example from the F-15C.

First, my AddtoDataDefs call:

C++:
for (int i = 1; i < 15; i++)
{
    char temp[32];
    sprintf(temp, "PAYLOAD STATION WEIGHT:%1d", i);
    SimConnect_AddToDataDefinition(hs, DEF_PLD, temp, "pounds");
};

Note the loop starts at 1 since the index value in the string name must start at 1.

Then my SetData call:

C++:
double pld[14] =
{
    lau128stores[acm.payloadstations[0]],
    wingstores[acm.payloadstations[1]],
    lau128stores[acm.payloadstations[2]],
    bellystores[acm.payloadstations[3]],
    bellystores[acm.payloadstations[4]],
    ctrstores[acm.payloadstations[5]],
    bellystores[acm.payloadstations[6]],
    bellystores[acm.payloadstations[7]],
    lau128stores[acm.payloadstations[8]],
    wingstores[acm.payloadstations[9]],
    lau128stores[acm.payloadstations[10]],
    acm.gunround ? 940 * 0.557 : 940 * 0.5732,
    acm.chaff*0.4,
    acm.flares*0.7
};
SimConnect_SetDataOnSimObject(hSc, DEF_PLD, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(pld), pld);
 
OK I got it to work. Two pointers for "the next guy"

1) Note Jon's syntax of passing the total array size in bytes, instead of using the unitSize and arrayCount parameters.
2) The size of the data that you send to SetDataOnSimObject must be exactly equal to the total size of the data definition.

Farley
 
Back
Top