Jump to content
The simFlight Network Forums

reverse axis in LUA script


Recommended Posts

Hello Pete,

as I'm not the big mathematician, I hope you could help me a bit:

I have a LUA script assigned to an axis.

Working so far.

But I want the axis now the other way round:

var = round((ipcPARAM+16384)/32768*100)

Now, var is 100 at 16384 and I want var to be zero at 16384 and 100 at -16834

("round" is a selfmade function for roundings as you surely assume)

There must be somewhere a -1 inserted, could you point me please to the right direction?

many thanks!

Günter

Link to comment
Share on other sites

var = round((ipcPARAM+16384)/32768*100)

Now, var is 100 at 16384 and I want var to be zero at 16384 and 100 at -16834

If that's the case it would be clearer written as

var = ((ipcPARAM+16384) * 100)/32768

because it is ambiguous the way you have it -- whether the multiplication is done before the division, as would probably be assumed in normal everyday notation.

("round" is a selfmade function for roundings as you surely assume)

If you are writing "var" back as an integer it will be rounded down to the nearest integer in any case. To round up or down to the nearest, just add 0.5 first. i.e.

var = 0.5 + (((ipcPARAM + 16384) * 100) / 32768)

Finally, assuming ipcPARAM is running from 0 to 16384, as you are implying, to reverse it all you need to do is subtract it from 16384, so:

var = 0.5 + ((((16384 - ipcPARAM) + 16384) * 100) / 32768)

Pete

Link to comment
Share on other sites

Many thanks Pete,

outstanding service as always!!!

Substracting from 16384 was the magic trick :)

"If you are writing "var" back as an unteger it will be rounded down to the nearest integer in any case. To round up or down to the nearest, just add 0.5 first. i.e."

Ah, ok will try that.

Looks like a lot better then my "trick"

many thanks and many greetings!

Günter

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.