Struggling with LUA and the basics

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Message
Author
Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Struggling with LUA and the basics

#21 Post by Kaellis991 »

jph wrote: Tue Oct 04, 2022 7:21 am Kirk, If the real aircraft switch can be energised to pull the lever switch on via the electromagnet, and yours is the same unit, then it should work.
I believe you are using 14V. (I don't know why you chose that figure ?) What is the real aircraft using ? - possibly 28V. - or more importantly, what was the part you have designed for ?
If that is the case then you should change the PSU to 24 / 28 V, but check first.

Joe
Here is the answer to the autopilot switch functions. It appears that Justflight added that autopilot feature of automatically toggling on the A/P master when the HDG switch is placed in the ON position.
That Piper Arrow sim and their autopilot control does not exactly mimic the real world operation.
There is no way the magnet can "pull" that switch to the on position.
image.png

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: Struggling with LUA and the basics

#22 Post by SimPassion »

Kaellis991 wrote: Tue Oct 04, 2022 9:47 am
SimPassion wrote: Tue Oct 04, 2022 8:09 am
Kaellis991 wrote: Mon Oct 03, 2022 10:18 pm .../...
Again, what does the asterisk do? The * between position and the 2 value.

Thanks for your help with this.
Yes the * is used as the multiply sign in "position * 2"
But why? Never have seen that in any code example.
Hi Kirk, it's only a solution based on the values you were expecting initially
On scripting concern, there's many best practices and solutions we can choose through, in order to find our way we want to bring code. Other would have made differently

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

Re: Struggling with LUA and the basics

#23 Post by jph »

Kaellis991 wrote: Tue Oct 04, 2022 2:26 pm
Here is the answer to the autopilot switch functions. It appears that Justflight added that autopilot feature of automatically toggling on the A/P master when the HDG switch is placed in the ON position.
That Piper Arrow sim and their autopilot control does not exactly mimic the real world operation.
There is no way the magnet can "pull" that switch to the on position.
Thanks Kirk, that seems eminently sensible and logical. They also do not appear to be the kind of electromagnetic unit that would engage a switch from cold.
I was looking at some PIPER voltages and it appears the early aircraft were 14V and on some models they changed to 28V in the early to mid 80's so 14V will certainly be correct for yours. The 'getting warm' on higher voltages also is a giveaway.
You CAN make the aircraft behave as per the real aircraft regardless of the way they have done it as you have full control over the switches and actions. But, get it working as it is first. ;)
Joe
Joe. CISSP, MSc.

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Struggling with LUA and the basics

#24 Post by Kaellis991 »

The autopilot is now working the same as the real thing....Another hurdle closer to the finish line thanks to SimPassion.
My next, and I think last, project will be finding a way to power off the landing gear indicator lights when the battery switch goes to off.
Maybe its just some code writing, or using the MOSFET that just arrived from Digikey.

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Struggling with LUA and the basics

#25 Post by Kaellis991 »

SimPassion wrote: Tue Oct 04, 2022 2:42 pm
Kaellis991 wrote: Tue Oct 04, 2022 9:47 am
SimPassion wrote: Tue Oct 04, 2022 8:09 am

Yes the * is used as the multiply sign in "position * 2"
But why? Never have seen that in any code example.
Hi Kirk, it's only a solution based on the values you were expecting initially
On scripting concern, there's many best practices and solutions we can choose through, in order to find our way we want to bring code. Other would have made differently
Sorry to be such a pain, but I dont really understand what you are saying there. Does the asterisk mutiply the value of the variable 'position' by 2 to produce a new number? That multiplication symbol is not described in any of the examples from the siminnovations wiki pages that I can find.

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: Struggling with LUA and the basics

#26 Post by SimPassion »

Kaellis991 wrote: Tue Oct 04, 2022 9:51 pm .../...
1 - Does the asterisk mutiply the value of the variable 'position' by 2 to produce a new number?
2 - That multiplication symbol is not described in any of the examples from the siminnovations wiki pages that I can find.
1 - Exactly
2 - The value can be the result of a formula, which is by design in scripting, this is why it is not described in the WIKI. There, there's just room to go to the basic of LUA scripting, or even better to scripting in general

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Struggling with LUA and the basics

#27 Post by Kaellis991 »

SimPassion wrote: Tue Oct 04, 2022 10:32 pm
Kaellis991 wrote: Tue Oct 04, 2022 9:51 pm .../...
1 - Does the asterisk mutiply the value of the variable 'position' by 2 to produce a new number?
2 - That multiplication symbol is not described in any of the examples from the siminnovations wiki pages that I can find.
1 - Exactly
2 - The value can be the result of a formula, which is by design in scripting, this is why it is not described in the WIKI. There, there's just room to go to the basic of LUA scripting, or even better to scripting in general
Is that a part of basic LUA coding that might be described in LUA programming books? Does that use of a formula have a name so I could find it in the index of a LUA book?

So if I undrstand the use of the multipy....the variable 'position' can only be 0 or 1(the two switch positions of OFF or ON)
If you multiply 0 * 2 you will get 0. The switch is OFF.
And if you multply 1 * 2 you get 2. The switch is ON in the case of this particular dataref being written to.
So the number that is sent to the dataref will be either 0 or 2 which is determined by the multiplication.

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: Struggling with LUA and the basics

#28 Post by SimPassion »

Kaellis991 wrote: Tue Oct 04, 2022 10:50 pm 1 - Is that a part of basic LUA coding that might be described in LUA programming books? Does that use of a formula have a name so I could find it in the index of a LUA book?

2 - So if I undrstand the use of the multipy....the variable 'position' can only be 0 or 1(the two switch positions of OFF or ON)
If you multiply 0 * 2 you will get 0. The switch is OFF.
And if you multply 1 * 2 you get 2. The switch is ON in the case of this particular dataref being written to.
So the number that is sent to the dataref will be either 0 or 2 which is determined by the multiplication.
1 - It's by design in modern scripting languages, where we can use formula rather than direct values or a single variable. Not sure we can find that simple explanation in books. Just use operators on personal taste, to fulfill your specific needs when coding.
2 - Correct, as it was stated in the script comment here : https://siminnovations.com/forums/viewt ... 143#p49143
Last edited by SimPassion on Thu Oct 06, 2022 2:10 am, edited 1 time in total.

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Struggling with LUA and the basics

#29 Post by Kaellis991 »

Some things you just cant learn from books...

Post Reply