January 25, 201610 yr Hi Scot. I keep running into an issue with a variable within a function that I can solve but I do not like the solution. I use a Saitek Yoke and throttle with the switch panel and I set each button/switch with 2 tasks. To call one or the other, i use button 1 on the yoke to select the second task and when not pressed, the first task is called within each function a signed to different switches, every one of my functions are in the action.lua file inside my aircraft folder. Here is an example of what I am doing. -- asigned to an unused button on the switch pane. function InitVars () BShift = 0 end -- Use On Press Button 1 function BShiftOn () BShift = 1 end -- -- Use On Release Button 1 function BShiftOff () BShift = 0 end --and then I have all of my functions in the action.lua file as below function PropSyncSW_or_PropGovTestSW () if BShift == 0 then ipc.control(66287) -- Toggle Prop Sync Switch ipc.control (65823, 1) -- knob sound ipc.control (65823, 0) -- knob sound elseif BShift == 1 then local PropGov = ipc.readLvar("B200propgov_sw") if PropGov == 0 then ipc.readLvar("B200propgov_sw",1) ipc.control (65823, 1) -- knob sound ipc.control (65823, 0) -- knob sound elseif PropGov == 1 then ipc.readLvar("B200propgov_sw",0) ipc.control (65823, 1) -- knob sound ipc.control (65823, 0) -- knob sound end end BShift = 0 -- this is what I do not want to do.end At times, the BShift variable gets stuck to a 1 and stays at that value. I have to run InitVars where BShift = 0 to get it working again. To solve this issue I have to put BShift = 0 at the end of each function but that means I have to release and repress-press button one when I am using multiple functions in a row where BShift needs to be a 1. Any ideas as to why when I release button 1 the BShiftOff function is not run on On Release of button 1 or is there a better way of calling 2 differant tasks/functions for each button? An example would be paging through differat views and using button 1 to change direction back to the first view, the VC. Thanks
January 27, 201610 yr Author I solved this issue by taking, I believe a better approach. Instead of relying on a variable within a function I wrote a 1 to offset to 66C0 when button 1 is pleased and a 0 when released. I created a function to read the offset address and called that function in the beginning of each 2 task function. -- Use On Press Button 1 function BShiftOn () ipc.writeDD(0x66C0, 1) end -- -- Use On Release Button 1 function BShiftOff () ipc.writeDD(0x66C0, 0) end function BShiftRead () BShift = ipc.readDD(0x66C0) end
Create an account or sign in to comment