MartinJ 69 Posted June 1, 2015 Report Share Posted June 1, 2015 Hi guys, here's a snippet of the code of my Airbus A310 project. if local_dref_getInt(id_a310_elec_pb_idg2_status) == 1 and a310_elec_pb_idg2_timer_started == 0 then --start timer to automatically close the cover after the time is up a310_elec_pb_idg2_timer_started = 1 a310_elec_pb_idg2_timer = timer.newOneShot('a310_function_idg2_timer', 5.0) timer.destroy(a310_elec_pb_idg2_timer) end if local_dref_getInt(id_a310_elec_pb_idg2_status) == 2 and local_dref_getFloat(id_a310_elec_pb_idg2_anim) == 2.0 then --close the cover if the button has been pressed a310_elec_pb_idg2_timer_started = 0 end This code runs without a problem but it makes no sense because the timer is destroyed right after it's being created. So the following code actually makes a lot more sense: if local_dref_getInt(id_a310_elec_pb_idg2_status) == 1 and a310_elec_pb_idg2_timer_started == 0 then --start timer to automatically close the cover after the time is up a310_elec_pb_idg2_timer_started = 1 a310_elec_pb_idg2_timer = timer.newOneShot('a310_function_idg2_timer', 5.0) end if local_dref_getInt(id_a310_elec_pb_idg2_status) == 2 and local_dref_getFloat(id_a310_elec_pb_idg2_anim) == 2.0 then --close the cover if the button has been pressed a310_elec_pb_idg2_timer_started = 0 timer.destroy(a310_elec_pb_idg2_timer) end The only difference is that I moved the timer.destroy command from the first if-clause to the second one. When I run this code x-plane crashes when the second if-clause is entered. Do you guys have any ideas on what's causing the crash? Kind regardsMartin Quote Link to post Share on other sites
Ben Russell 1,008 Posted June 1, 2015 Report Share Posted June 1, 2015 Gizmo needs a new timer API call to allow you to query the state of a timer handle. Eg:if( timer.isAlive( a310_elec_pb_idg2_timer ) )then timer.destroy( a310_elec_pb_idg2_timer )end I'll be adding this(or something very similar) in the near future. For now you'll have to use ugly guard flag variables to "know things" about timers that the API should be able to tell you directly. The crash is caused because the timer has probably expired and been destroyed already as it's a one-shot item.The fix is to either use a separate additional variable to track the state of the timer or wait for the new API call. Thanks for using Gizmo. Quote Link to post Share on other sites
MartinJ 69 Posted June 3, 2015 Author Report Share Posted June 3, 2015 Thank you for you answer Ben. I added an additional check before destroying the timer and now everything is fine. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.