-
Hi everyone, Sorry to ask that, I'm discovering all that simconnect stuff... So far, I managed to create an aircraft using the AICreateNonATCAircraft function. I can see the aircraft on the ground, everything is fine. Now, I'd like to move that aircraft. I wanted to use the SetDataOnSimObject function, but I definitely don't understand how to use it. How to get the definition ID and the object ID? Could someone provide me an example please? Thanks a lot for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi! Thanks for reaching out! Assuming that function works similar to AICreateEnrouteATCAircraft, subscribing to the system event EDIT: like this enum MY_EVENT_ID {
OBJECT_ADDED_EVENT,
OBJECT_REMOVED_EVENT,
};
// Clean up previous subscriptions, if any
handle.unsubscribeFromSystemEvent(MY_EVENT_ID.OBJECT_ADDED_EVENT)
handle.unsubscribeFromSystemEvent(MY_EVENT_ID.OBJECT_REMOVED_EVENT)
handle.subscribeToSystemEvent(MY_EVENT_ID.OBJECT_ADDED_EVENT, "ObjectAdded")
handle.subscribeToSystemEvent(MY_EVENT_ID.OBJECT_REMOVED_EVENT , "ObjectRemoved")
handle.on("eventAddRemove", (e) => {
switch(e.clientEventId) {
case MY_EVENT_ID.OBJECT_ADDED_EVENT:
console.log(`${SimObjectType[e.type]} was added with simobject ID ${e.data}`)
break;
case MY_EVENT_ID.OBJECT_REMOVED_EVENT:
console.log(`${SimObjectType[e.type]} with ID ${e.data} was removed`)
break;
}
});
const spawnPosition = new InitPosition()
spawnPosition.latitude = 60.19669814227938
spawnPosition.longitude = 11.094849220919981
spawnPosition.onGround = true
handle.aICreateNonATCAircraft("DA62 Asobo", "LN-ABC", spawnPosition, 1234) |
Beta Was this translation helpful? Give feedback.
-
Regarding the data definition ID this must be created in the same way you would do when requesting or setting simvars on the user's aircraft. The data definition is used to describe the contents of the data chunk you will be sending. The definition should be created once and reused whenever you need to send the same set of simvars. Example: // Define the data structure (done once)
const PLANE_POSITION_DEFINITION_ID = 123;
handle.addToDataDefinition(PLANE_POSITION_DEFINITION_ID, 'Plane Latitude', 'degrees', SimConnectDataType.FLOAT64);
handle.addToDataDefinition(PLANE_POSITION_DEFINITION_ID, 'Plane Longitude', 'degrees', SimConnectDataType.FLOAT64);
// Prepare the data blob to send
const dataChunk = new RawBuffer(1)
dataChunk.writeFloat64(60.1968)
dataChunk.writeFloat64(11.0949)
// Send the updated position
handle.setDataOnSimObject(PLANE_POSITION_DEFINITION_ID, spawnedAircraftId, {
buffer: dataChunk,
arrayCount: 0,
tagged: false,
}) |
Beta Was this translation helpful? Give feedback.
Regarding the data definition ID this must be created in the same way you would do when requesting or setting simvars on the user's aircraft. The data definition is used to describe the contents of the data chunk you will be sending. The definition should be created once and reused whenever you need to send the same set of simvars.
Example: