The Tall Guy Posted March 13, 2011 Report Share Posted March 13, 2011 Hi, Pete! I'm new to FSUIPC but I'm loving it! The Lua libraries, in particular, are great, and allowing me to really improve my sim experience. I am working on a Lua script that overloads the functions of the buttons on my game controller. (I sim on my laptop, and when I'm not at my desk rig, I use a game controller.) This script, inspired by your "tripleuse.lua" example, lets me assign functions that are invoked on button down, button up and button hold, and can be repeating or "only once". This is all on Windows XP SP3 and FS 9.1 using FSUIPC 3.989y (version verified on the main window). I'm noticing some odd behavior, and I can't tell if they are mistakes I'm making or bugs in FSUIPC. I thought I should bring them to your attention. 1. My initial approach was to capture button presses and test for button releases using ipc.testbutton, as in "tripleuse". This worked brilliantly for the normal buttons (0-31). For the POV buttons, however, this didn't work well. The capture events happened as expected, but ipc.testbutton always returned false, even when the POV button was down. Is this the correct behavior? The docs aren't specific on it one way or another. 2. Since I couldn't get "testbutton" to do what I needed, I changed the code to use event.timer instead; I track presses/releases myself, and on button press I start a timer. The timer function checks to see if buttons are still down, and performs the button "hold" functions. When the button is released, I use "event.cancel" to terminate the timer. However, i get what looks like a low-level Lua error in the script's log. Here's the code to start the timer: function ActionButton.startTimer() ActionButton.timerCount = ActionButton.timerCount and ActionButton.timerCount + 1 or 1 -- how many buttons we're watching if ActionButton.timerCount == 1 then -- no timer running yet event.timer( ActionButton.timerInterval, "ActionButton.timerEvent" ) print( "ActionButton.startTimer: Timer started" ) end end and the code to cancel it: function ActionButton.endTimer() ActionButton.timerCount = ActionButton.timerCount - 1 if ActionButton.timerCount < 1 then -- no more keys to monitor... event.cancel( "ActionButton.timerEvent" ) -- so shut down the timer print( "ActionButton.endTimer: Timer stopped" ) end end And this is the error that shows up in the log later on: 39234500 *** LUA Error: attempt to call a nil value Note the lack of line numbers. When I comment out the event.cancel, the error goes away. Thanks in advance for any insight you can provide into these. I'm happy to provide the entire script if you like, but it's quite long so I thought I'd start with small fragments. Best, Michael Link to comment Share on other sites More sharing options...
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 account
Already have an account? Sign in here.Sign In Now