draci Posted January 26 Report Share Posted January 26 Hi everyone, I have an add-on that randomly triggers brakes failures in my sim which is really annoying. The only FS controls I found are toggle_left/right_brake_failure which are controls 66311 and 66312. The following simple lua script brakesresetevent.lua intends to reset the brake-failures when ever they occur randomly. The second script brakesevent.lua (further below) should give me the opportunity to overrule the resetting such that I can sill fail the brakes if I intend to. brakesresetevent.lua: ipc.set("leftFailed",1) ipc.set("rightFailed",1) local lfail = 0 local rfail = 0 function leftreset() lfail = ipc.get("leftFailed") if(lfail == 1) then ipc.set("leftFailed",0) ipc.control(66311) ipc.sleep(1000) ipc.set("leftFailed",1) end end function rightreset() rfail = ipc.get("rightFailed") if(rfail == 1) then ipc.set("rightFailed",0) ipc.control(66312) ipc.sleep(1000) ipc.set("rightFailed",1) end end event.control(66311, "leftreset") event.control(66312, "rightreset") The problem is that although I try to prevent recursive triggering of the event with the global vars leftFailed and rightFailed this seems to happen. In general lua there is the possibility to temporarily unregister and reregister an event. Is this also possible in FSUIPC? brakesevent.lua: ipc.set("LeftFailed",0) ipc.set("RightFailed",0) ipc.sleep(200) ipc.control(66311,0) ipc.sleep(100) ipc.control(66312, 0) ipc.sleep(200) ipc.set("LeftFailed",1) ipc.set("RightFailed",1) ipc.runlua("brakesresetevent") The idea is the following: The first script runs from the beginning of the sim session (Run by FSUIPC.cfg). Whenever I hit the key combo, the first script gets killed by KillLua and the second script is started when releasing the key combo. That's why I restart the continuously running first script at the end of the second script by ipc.runlua. However, whatever I try I get recursive callbacks since the brakes flicker wildly from on to off. I'd appreciate if anybody could help me see my mistake. regards draci Link to comment Share on other sites More sharing options...
draci Posted January 27 Author Report Share Posted January 27 Corrected the typo: leftFailed <-> LeftFailed and rightFailed <-> RightFailed, but still no success. Link to comment Share on other sites More sharing options...
John Dowson Posted January 29 Report Share Posted January 29 On 1/26/2024 at 11:42 PM, draci said: In general lua there is the possibility to temporarily unregister and reregister an event. Is this also possible in FSUIPC? You can use event.cancel to remove all event tracking on the same function. On 1/26/2024 at 11:42 PM, draci said: The idea is the following: The first script runs from the beginning of the sim session (Run by FSUIPC.cfg). Whenever I hit the key combo, the first script gets killed by KillLua and the second script is started when releasing the key combo. That's why I restart the continuously running first script at the end of the second script by ipc.runlua. However, whatever I try I get recursive callbacks since the brakes flicker wildly from on to off. I'd appreciate if anybody could help me see my mistake. This seems overly complicated. Why not just use one script that has a flag (or two) which determine if the brakes should fail or not. You can then set/clear these flags by using an ipcParam variable, and using an event.param function in your script, and assigning with LuaValue to tell the script when to set and clear the brakes failure flags. John Link to comment Share on other sites More sharing options...
draci Posted January 29 Author Report Share Posted January 29 Thank you John, I'm going to try your suggestions. Link to comment Share on other sites More sharing options...
draci Posted February 7 Author Report Share Posted February 7 Ok, I have tried to reset the P3D brakes failure via .lua scripts for weeks without success. Here's what my main problems are: 1. Writing to the offset 0B63 with ipc.setbitsUB and ipc.clearbitsUB doesn't work. The failure in the PMDG->Vehicles->Failure Menu persists for Left and Right Brake. 2. Toggling FS-controls 66310-66312 via ipc.control(6631x) in order to reset randomly occurring failures doesn't work either or seems to end up in infinite recursions since event.control(6631x,"callback") is called everytime the callback-function calls ipc.control(6631x). Cancelling the recursion via event.cancel("callback") does not help. 3. The FSUIPC Fs-controls "Toggle Left/Righ/All Brakes Failure" surprsingly DO work to trigger a failure, however, repeated use doesn't clear the failure. However, since there are Add-Ons like FS-Flight Control which can both trigger and reset failures, there must be a way to control the failure state somehow. My lua scripts are correct and FSUIPC Debugging/Tracing for them doesn't reveal any issues with my code, the logic runs as intended. What else can I try? Link to comment Share on other sites More sharing options...
John Dowson Posted February 7 Report Share Posted February 7 13 hours ago, draci said: 1. Writing to the offset 0B63 with ipc.setbitsUB and ipc.clearbitsUB doesn't work. The failure in the PMDG->Vehicles->Failure Menu persists for Left and Right Brake. Try logging offset 0B63 (as U8 in Hex) to see if this offset is being used. Does it update correctly when using the PMDG->Vehicles->Failure Menu? If you also log events, what events do you see? When your lua script sets/clears the bits in this offset, do you see the same values and events? As you are using a PMDG aircraft (which one?), it may not be responding to standard FS controls. 13 hours ago, draci said: 2. Toggling FS-controls 66310-66312 via ipc.control(6631x) in order to reset randomly occurring failures doesn't work either or seems to end up in infinite recursions since event.control(6631x,"callback") is called everytime the callback-function calls ipc.control(6631x). Cancelling the recursion via event.cancel("callback") does not help. Again, use logging. If you are sending the same control in an event callback that is handling the control, then you will get into an infinite recursive loop. Maybe check the event parameter - is this different between a toggle on and a toggle off (some toggle controls do use a parameter)? If so, you can use that to distinguish between toggle on and toggle off, and only send the control for one parameter. Otherwise, try using event.offset instead, and again only send the required control when needed. 13 hours ago, draci said: 3. The FSUIPC Fs-controls "Toggle Left/Righ/All Brakes Failure" surprsingly DO work to trigger a failure, however, repeated use doesn't clear the failure. What events do you see when you use the menu to toggle failures on and off? Check if a parameter is needed. If you need further help, please show me your lua script, and your ini and log files, the latter with logging for Events activated as well as logging for offset 0B63, and maybe also lua plugin logging. One log file should show you toggling and clearing the brake failure via the PMDG menu (without your lua running), and another log file showing what you are trying to achieve with your lua script running. Link to comment Share on other sites More sharing options...
draci Posted February 22 Author Report Share Posted February 22 Wrote a little simconnect client to implement the above functionality. Works without any problems, no recursive calls at all, brakes failures efficiently blocked, me a happy camper. 🙂 Link to comment Share on other sites More sharing options...
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