I am attempting to set some data on AI aircraft in Microsoft Flight Simulator X - and I can! But only exactly one time! My program needs to set this data in a loop as it is continuously changing. Here is the method I am calling to update the locations, and my print statements are printing every time this method is called, however when in the game the planes position only updates one time! I am unsure what I am doing wrong, any help would be greatly appreciated!
Thank You!
void movePlaneToNewPosition()
{
HRESULT hr;
SIMCONNECT_DATA_INITPOSITION Initi;
Initi.Altitude = 500.0;
Initi.Latitude = 39.4513;
Initi.Longitude = -74.5722;
Initi.Pitch = 0.0;
Initi.Bank = -1.0;
Initi.Heading = 180.0;
Initi.OnGround = 0;
Initi.Airspeed = 350;
if(realPlaneTargetID.find("NoPlaneLOL"))
{
printf("nWE have the correct plane! ID: %dn",BoeingPlaneID);
SIMCONNECT_DATA_INITPOSITION Initi;
Initi.Altitude = atof(realPlaneAltitude.c_str());
Initi.Latitude = atof(realPlaneLatitude.c_str());
Initi.Longitude = atof(realPlaneLongitude.c_str());
Initi.Pitch = 0.0;
Initi.Bank = -1.0;
Initi.Heading = atof(realPlaneHeading.c_str());
Initi.OnGround = 0;
Initi.Airspeed = atof(realPlaneSpeed.c_str());
}
printf("THE METHOD IS GETTING CALLED, IDK WHY IT WONT WORK A SECOND TIME");
//hr = SimCoect_AddToDataDefinition(hSimCoect, DEFINITION_9, "Initial Position", NULL, SIMCONNECT_DATATYPE_INITPOSITION);
hr = SimCoect_SetDataOnSimObject(hSimCoect, DEFINITION_9, BoeingPlaneID, 0, 0, sizeof(Initi), &Initi );
hr = SimCoect_AddToDataDefinition(hSimCoect, DEFINITION_9, "Initial Position", NULL, SIMCONNECT_DATATYPE_INITPOSITION);
if(hr == S_OK)
{
printf(" n Set data PASS");
}
if(hr == E_FAIL)
{
printf(" nSet data FAIL");
}
//hr = SimCoect_AddToDataDefinition(hSimCoect, DEFINITION_6, "Initial Position", NULL, SIMCONNECT_DATATYPE_INITPOSITION);
printf("n MovePlane Boeing 747 ID = %d", BoeingPlaneID);
if(hr == S_OK)
{
printf(" n Aircraft has been moved");
}
if(hr == E_FAIL)
{
printf(" n Failed at movePlanToNewPosition");
}
}
