Jump to content
The simFlight Network Forums

LUA help needed


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.