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

##### Share on other sites

Günter,

Rev_Axis = abs(var - 100)

Just subtract 100 from the 0 to 100 "var" and then take the absolute value.

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

Paul

##### 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

##### 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

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible. ×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.