Achoriham Posted December 30, 2010 Report Posted December 30, 2010 Hi, If anyone could help me, it would be truly appreciated. I'm trying to regulate the FSX throttle values via a small LUA plugin, as I'm trying to have some fix throttle values for a ship in FSX. I tried this: while 1 do ipc.sleep(50) Throttle1 = ipc.readSW(0x088C) Throttle2 = ipc.readSW(0x0924) if ((Throttle1 < 330) and (Throttle1 < -500)) then Throttle1Out = 0 Throttle2Out = 0 ipc.writeSW(0x088C, Throttle1Out) ipc.writeSW(0x0924, Throttle2Out) else if ((Throttle1 > 330) and (Throttle1 < 5800)) then Throttle1Out = 4000 Throttle2Out = 4000 ipc.writeSW(0x088C, Throttle1Out) ipc.writeSW(0x0924, Throttle2Out) else if ((Throttle1 > 3500) and (Throttle1 < 5800)) then Throttle1Out = 8000 Throttle2Out = 8000 ipc.writeSW(0x088C, Throttle1Out) ipc.writeSW(0x0924, Throttle2Out) else if ((Throttle1 > 5800) and (Throttle1 < 8600)) then Throttle1Out = 12000 Throttle2Out = 12000 ipc.writeSW(0x088C, Throttle1Out) ipc.writeSW(0x0924, Throttle2Out) else if (Throttle1 > 8600) then Throttle1Out = 16300 Throttle2Out = 16300 ipc.writeSW(0x088C, Throttle1Out) ipc.writeSW(0x0924, Throttle2Out) end end end end end end But it doesn't work, value 0 and the max works but nothing in between. What do I do wrong? thanks in advance Potroh
Pete Dowson Posted December 30, 2010 Report Posted December 30, 2010 I tried this: Look at what you have: First: if ((Throttle1 < 330) and (Throttle1 < -500)) then if the value is less than -500 it must be less than 330, so you can simplify that to if (Throttle1 < -500) then and all of your places like this: Throttle1Out = 0 Throttle2Out = 0 ipc.writeSW(0x088C, Throttle1Out) ipc.writeSW(0x0924, Throttle2Out) would be more efficient as: ipc.writeSW(0x088C, 0) ipc.writeSW(0x0924, 0) The next condition: if ((Throttle1 > 330) and (Throttle1 < 5800)) then leaves the gap between -500 and 330, but whwen it operates it sets 4000, which is then changed on the next loop by: if ((Throttle1 > 3500) and (Throttle1 < 5800)) then into 8000, which is then changed by the next one: if ((Throttle1 > 5800) and (Throttle1 < 8600)) then into 12000 and finally by if (Throttle1 > 8600) then into 16300. Thus you can only ever get -500 to 330, or 16300 resulting. To find bugs in code, work through it yourself as if you were the computer, making the changes. You will quickly see that in as few as 4 or 5 loops (200-250 mSecs) your values are restricted to those! Pete
Achoriham Posted December 30, 2010 Author Report Posted December 30, 2010 Hi Pete, Many thanks for your help! I used a different offset at 66C0 and 66C2 to drive the hardware levers and write those to the usual throttle offsets, so it is working perfectly now. thanks again Potroh
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