ark1320 Posted March 27, 2017 Report Posted March 27, 2017 Hi Pete, I am using the command event.offset(offset, "type", "function-name) in a script that is listed under [Auto] in the FSIPC.ini.file. My questions are: 1. If the command makes two sequential calls of “function-name” and the first called function is still running when the second call occurs, are there now two instances of the function running, or did the second call terminate the first function? 2. If two instances of the called function would be running (which is what I think), what might be a good way to terminate the first function when the second call is made? Thx, Al
Pete Dowson Posted March 27, 2017 Report Posted March 27, 2017 4 hours ago, ark1320 said: If the command makes two sequential calls of “function-name” and the first called function is still running when the second call occurs, are there now two instances of the function running, or did the second call terminate the first function? The first one will be called and when that exits, the second may or may not also be called, depending on the state of the offset by then. You never get more than one thread per plug-in (unless you use so rather esoteric external Lua libraries, not supplied with FSUIPC). 4 hours ago, ark1320 said: If two instances of the called function would be running (which is what I think), what might be a good way to terminate the first function when the second call is made? Really it is not logical to have two for the same event. However, taking your question literally, the swecond function doesn't need to terminate the first because the second one cannot run whilst the first is still running, so when it does run the first is already terminated. But taking the question the way you might have meant, you stop an event function being called by using the event.cancel function. But best, and more logical, you should declare only one function for the event, and then, when you want to change which function to call for the next such event, before exiting, use event.cancel then event.offset within the code in the first function. It won't be called until the next time the event is signalled. Pete
ark1320 Posted March 27, 2017 Author Report Posted March 27, 2017 To clarify a bit, my situation is that the function called by event.offset() is logging aircraft data and may typically run for 8 to 10 seconds. During that time, the location being monitored by event.offset could change so as to trigger a second call to the same logging function while the first is still running, and thus my questions above. Thanks very much for the help. Al
Pete Dowson Posted March 27, 2017 Report Posted March 27, 2017 40 minutes ago, ark1320 said: During that time, the location being monitored by event.offset could change so as to trigger a second call to the same logging function while the first is still running, That cannot happen. Whilst the thread created for your plug-in is running, no events will be checked for your plug-in. The event, when it occurs, is simply flagged in an event list for your plug-in, and those flags are checked in-line, within your plug-in's thread, when it exits the function. Also events are not queued, you only get one call no matter how many times the offset changes whilst your plug-in is executing the function. Pete
ark1320 Posted March 27, 2017 Author Report Posted March 27, 2017 Pete -- thanks very much for the further explanation -- very helpful. A related question please: the event being monitored by event.offset() is the on-ground flag in offset 0x0366 which has a value of 1 when the aircraft is on the ground. If the aircraft bounces during landing, and thus is only on the ground for a small fraction of a second perhaps during the bounce, is there a reasonable chance the bounce will be 'missed' as far as the on-ground flag is concerned because of sim or script timing issues (e.g., the sim was busy doing other things when the bounce occurred and so the on-ground flag didn't change)? Thx, Al
Pete Dowson Posted March 27, 2017 Report Posted March 27, 2017 4 hours ago, ark1320 said: If the aircraft bounces during landing, and thus is only on the ground for a small fraction of a second perhaps during the bounce, is there a reasonable chance the bounce will be 'missed' as far as the on-ground flag is concerned because of sim or script timing issues (e.g., the sim was busy doing other things when the bounce occurred and so the on-ground flag didn't change)? I should think that this would be a possibility. It might be better to monitor the vertical speed or acceleration if you need such information. You might need to experiment. Pete
ark1320 Posted April 2, 2017 Author Report Posted April 2, 2017 Hi Pete, The documentation on event.offset() says "The function is also executed initially, when the plugin is first run, in order to initialise things". In my application, event.offset() is used inside a nested function. That is, function A calls function B, and event.offset is part of function B and calls function C when the offset changes. However, if I understand correctly, the initial execution of function C will happen the first time function B is called even if the offset has not changed value -- is that correct? Thanks, Al
Pete Dowson Posted April 2, 2017 Report Posted April 2, 2017 3 hours ago, ark1320 said: However, if I understand correctly, the initial execution of function C will happen the first time function B is called even if the offset has not changed value -- is that correct? Probably. I'd need to try it to be sure. But C won't be called till B has finished and exited in any case. I don't know off-hand whether the flag to tell it to execute the new event is carried forward till then, but I think it is very likely. It should be easy enough to check. Just use ipc.log to give a message on entry to each. Pete
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now