Steve Johnson Posted August 23, 2016 Report Share Posted August 23, 2016 Hi Peter, my Lua programming has hit a wall. I have installed a home made GEN AMP stepper instrument which operates from an offset. I can easily set it up to work from an FSX offset 2888. However I am using an add on for the aircraft which gives a much more accurate reading and simulates much more of the electrical system. I know how to read from the add on programs local variables in Lua and to write to a custom offset. I can read from from the add on program and write it to custom offset using ipc.writeDBL and display it to the screen through FSUIPC. i.e. 30.0000. The problem I have is that I have used all of the custom offset range right through to 66FF and I only have one offset available. The value range represented by the internal variable I am reading from is only 0 - 30, but it is stored in a floating point 64 type variable which uses 8 bytes or 8 offsets. My question is, is there a way to extract the value and convert it to one byte with the value been within that range (no need for fractions)? My plan B was to manually convert by writing ipc.readDBL(0x2888,myVariable) If myVariable = 30.0000 Then myVariable = 30 ipc.writeUB (0x66D4,myVariable) but this did not work :( Any help would be greatly appreciated. Regards Steve Link to comment Share on other sites More sharing options...
moskito-x Posted August 23, 2016 Report Share Posted August 23, 2016 Hello Steve You could use math.floor(x) Returns the largest integer smaller than or equal to x. Or a function function toint(n) local s = tostring(n) local i, j = s:find('%.') if i then return tonumber(s:sub(1, i-1)) else return n end end Thomas Link to comment Share on other sites More sharing options...
Steve Johnson Posted August 24, 2016 Author Report Share Posted August 24, 2016 Thanks for your reply. I will try this out at the weekend. Regards Steve Link to comment Share on other sites More sharing options...
Steve Johnson Posted August 29, 2016 Author Report Share Posted August 29, 2016 Hi. When I used math.floor(30.0000) as a test, it returned 30. As soon I replaced the number with my variable it would only return to a double floating point 64 type. Your function worked perfectly. Thank you very much for you help. Regards Steve Link to comment Share on other sites More sharing options...
moskito-x Posted August 29, 2016 Report Share Posted August 29, 2016 Hello Steve, Glad I could help ;-) Cheers Thomas Link to comment Share on other sites More sharing options...
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