Great Circle Distance calculator example (with altitude compensation) Lua

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Message
Author
SimPassion
Posts: 5339
Joined: Thu Jul 27, 2017 12:22 am

Re: Great Circle Distance calculator example (with altitude compensation) Lua

#11 Post by SimPassion »

Ralph wrote: Thu Dec 15, 2022 6:54 pm Isn't that the same as this function?
https://siminnovations.com/wiki/index.p ... c_distance
Thanks for this, very handy ! Indeed Altitude parameter would be useful too ...

User avatar
jph
Posts: 2856
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Great Circle Distance calculator example (with altitude compensation) Lua

#12 Post by jph »

SimPassion wrote: Fri Dec 16, 2022 11:27 am
Ralph wrote: Thu Dec 15, 2022 6:54 pm Isn't that the same as this function?
https://siminnovations.com/wiki/index.p ... c_distance
Thanks for this, very handy ! Indeed Altitude parameter would be useful too ...
Thank you and you are very welcome GIlles. I think as it currently the most elegant solution with altitude that can also be varied. Everything can be improved of course :lol:
Joe ;)
Joe. CISSP, MSc.

User avatar
jph
Posts: 2856
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Great Circle Distance calculator example (with altitude compensation) Lua

#13 Post by jph »

SimPassion wrote: Fri Dec 16, 2022 11:25 am
jph wrote: Fri Dec 16, 2022 9:42 am Thanks Ralph,
Altitude addition makes a heck of a lot of difference in calcs.
I can easily add the RHUMB option and also the various feet / meters / km / miles options etc if needed as the basic code is sorted.
Without altitude (which we never needed in sailing lol :lol: ) it is not as accurate for flight calculation.

One thing I found really useful during this experiment was the use of --[[ and --]] for lua code block comment. I had never previously seen that but searched for answers and eventually came across the --[[ and --]]
Rather nice.

You may well know this but I have not seen it in examples that I have looked at -try the following copy and past into AM

Code: Select all

-- this is a normal simple LUA comment

this is not a comment but will cause errors

--[[
this is a BLOCK comment in LUA. All comments are included in between the markers
So this is still included.
And this.
And even this.
this is how we end the block comment
--]]

x = 5 -- this is code followed by a comment

-- notice the difference ?

--[[ the difference is subtle but
extremely useful
Joe Hanley - 2022
I am sure it is pointed out on the wiki but i have missed it. Now I have found it I love it haha  (as the actress said to the bishop)
--]]
Great find, just noticed the ending tag "--]]" which is not obvious, though indeed logical, having "--" at first then "]]", as we used to rather inverted ones on the usual for example with c++ which is "/*" followed by "*/" and similar in multiple coding languages ... :o
Yes sir, it is specific, Previously I never found the LUA 'block' comment.. it was a revelation to say the least.
It is so strange that we often miss things that are in front of us. ;)
I love lua, it never ceases to amaze me with its total elegance and its total F&CK ups at the same time :lol: .. It really is very very nice though.
Joe
Joe. CISSP, MSc.

User avatar
jph
Posts: 2856
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Great Circle Distance calculator example (with altitude compensation) Lua

#14 Post by jph »

Honestly, I wonder how many have found the lua block comment ?

Code: Select all

--[[
text1
text2
text3
text4
--]]

I had never seen it used in ANY previous example with AM

:shock: :shock:

It can definitely be used more in descriptions and details

Joe
Joe. CISSP, MSc.

User avatar
Keith Baxter
Posts: 4685
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Great Circle Distance calculator example (with altitude compensation) Lua

#15 Post by Keith Baxter »

jph wrote: Fri Dec 16, 2022 12:20 pm Honestly, I wonder how many have found the lua block comment ?

Code: Select all

--[[
text1
text2
text3
text4
--]]

I had never seen it used in ANY previous example with AM

:shock: :shock:

It can definitely be used more in descriptions and details

Joe
Hi

I have used it often for years.
Did you find it in the commented out text in the clone instrument I posted in the AM4.2 bug thread??

Code: Select all

function CloseGuard(switch, yes)
  local s = gSwitch[switch]
  visible(s.img_closed, yes)
  visible(s.img_open, not yes)
  s.closed = yes
end
-- ====================== operate switches ==================
--[[
---------------------- Gen1 switch ----------------
local gSwitchGen1

function cbSwitchGen1(switch, dir)
  if dir > 0 then
    fs2020_event("ROTOR_BRAKE", 2701)
  else
    fs2020_event("ROTOR_BRAKE", 2702)
  end
end

fs2020_variable_subscribe("L:switch_27_73X", "number", function(v)
  SetSwitchPosition(gSwitchGen1, math.floor(v/50)+1)
end)

gSwitchGen1 = AddVerticalSwitch(105, 301, true, true, true, cbSwitchGen1)
]]
BTW. Just for info. The following is also good, no need for the --]], ]] will do.

Code: Select all

--[[
bla
blaa
]]
This is often used in commenting out blocks of code when debugging. Yes also good for commenting on code as well.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
jph
Posts: 2856
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Great Circle Distance calculator example (with altitude compensation) Lua

#16 Post by jph »

Hi Keith
Sorry but I didnt download the SIFF file. For small pieces of code, such as this, I much prefer the function itself to be embedded where possible so it can be copied and pasted.
But great to hear that you found it too. It had to be there somewhere as every other language I use or have used has a similar option available.
Thanks for the info.
Joe
Joe. CISSP, MSc.

Post Reply