Jump to content
The simFlight Network Forums

What am I doing wrong?


Recommended Posts

Pete,

Me again. I have written what I thought was a simple Lua plug-in to easily tune a chosen radio by simple entering the last 4 digits of the frequency after selecting the appropriate radio from a displayed menu i.e. 1 - Com1, 2 - Com2, etc. I can get the menu to display, and even the second part to work were I am able to "write" the frequency to the radio (i.e. I replace the first line in the code "whichradio=1" or "2"... and it then writes the freq to the correct radio). The only part that does not work is selecting the appropriate radio. I have no idea what is wrong; the code logically makes sense to me. I have been trying various thing for the last day now with no headway. I do not know whom else to ask, so could I bug you one more time so you may give me a nudge in the right direction?

whichradio=ipc.ask("Select Radio to Tune:\n\n1 - Com 1\n2 - Com 2\n3 - Nav 1\n4 - Nav 2")

if whichradio==1 then
Freq = ipc.ask("Enter Com 1 Frequency\n 1**.**")
decimalval = tonumber(Freq,16)
ipc.writeUW("034E",decimalval)
ipc.display("Com 1 Tuned to\n 1"..n, 2)
end

if whichradio==2 then
Freq = ipc.ask("Enter Com 2 Frequency\n 1**.**")
decimalval = tonumber(Freq,16)
ipc.writeUW("3118",decimalval)
ipc.display("Com 2 Tuned to\n 1"..Freq, 2)
end

---etc...

BTW, don't know were I can get a good book on Lua programming (Lua for Dummies)? This is getting addictive and I hate to be bothering you for your help, as I can appreciate that you are a busy person.

Jim

Link to comment
Share on other sites

I can get the menu to display, and even the second part to work were I am able to "write" the frequency to the radio (i.e. I replace the first line in the code "whichradio=1" or "2"... and it then writes the freq to the correct radio). The only part that does not work is selecting the appropriate radio.

...

if whichradio==1 then

Freq = ipc.ask("Enter Com 1 Frequency\n 1**.**")

decimalval = tonumber(Freq,16)

I think if you thought about it a little more you would relise that you really answered it yourself -- in the second case, the "tonumber".

In the line if whichradio==1 then the variable "whichradio" is a string -- ipc.ask returns a string, not a number. A string will never be equal to a number. You can USE a string as a number (Lua will automatically convert it for you), but comparisons don't do conversions. You have to compare like with like.

You can either do something like if whichradio == "1" then or, probably safer if tonumber(whichradio) == 1 then

BTW, don't know were I can get a good book on Lua programming (Lua for Dummies)?

http://www.amazon.co.uk/s/ref=nb_sb_nosua&x=0&y=0

The first two -- "Programming in Lua (2nd Edn)" and the Reference Manual are pretty essential. I haven't got the "Beginning..." one, but it doesn't look like its a "Dummies" type book judging by the synopsis!

Regards

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.