Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hello,

I have reached the boundary of my limited Lua knowledge, the relevant snippet of the script that I'm having difficulty with is below. I've commented what I hope to achieve which I expect will involve setting flags but I have no idea how to do this...

Any assistance will be very much appreciated and hope that my explanation is understandable

Thanks in advance

Paul


function NGX_NAV_INC(joy, btn, state)
--if NGX_SHIFT is pressed and NGX_NAV_SEL is pressed then NGX_NAV2_FRACT_INC()
--if NGX_SHIFT is pressed then NGX_NAV2_WHOLE_INC()
--if NGX_NAV_SEL is pressed then NGX_NAV1_FRACT_INC()
--else NAV1_WHOLE_INC()

function NGX_NAV_DEC(joy, btn, state)
--if NGX_SHIFT is pressed and NGX_NAV_SEL is pressed then NGX_NAV2_FRACT_DEC()
--if NGX_SHIFT is pressed then NGX_NAV2_WHOLE_DEC()
--if NGX_NAV_SEL is pressed then NGX_NAV1_FRACT_DEC()
--else NAV1_WHOLE_DEC()

function NGX_NAV1_WHOLE_INC()
ipc.control(65641)
end
function NGX_NAV1_WHOLE_DEC()
ipc.control(65640)
end
function NGX_NAV1_FRACT_INC()
ipc.control(65643)
end
function NGX_NAV1_FRACT_DEC()
ipc.control(65642)
end
function NGX_NAV2_WHOLE_INC()
ipc.control(65645)
end
function NGX_NAV2_WHOLE_DEC()
ipc.control(65644)
end
function NGX_NAV2_FRACT_INC()
ipc.control(65647)
end
function NGX_NAV2_FRACT_DEC()
ipc.control(65646)
end

event.button(4, 23, "NGX_SHIFT")
event.button(4, 6, "NGX_NAV_INC")
event.button(4, 7, "NGX_NAV_DEC")
event.button(4, 30, "NGX_NAV_SEL")

[/CODE]

Posted

I have reached the boundary of my limited Lua knowledge, the relevant snippet of the script that I'm having difficulty with is below. I've commented what I hope to achieve which I expect will involve setting flags but I have no idea how to do this...

First, may I ask why you are using Lua for this? It seems to me that you are using standard FS controls which can be assigned directly to buttons. All you then need to do is add button conditions in the FSUIPC INI file. The result will be much more compact and efficient. I can help with that if you like.

On the other hand, if you are using Lua specifically in order to improve your Lua capabilities, then I can help with that too. Your choice. If it's just the most practical answer you are after then conditional button assignments are really the way to go.

BTW I note you've named everything "NGX ..." but you do realise, I hope, that the controls you are using work with all FS radios, so it isn't going to be NGX specific.

Regards

Pete

Posted

Hello Pete,

Thanks as always for your quick reply.

I am using a number of Leo Bodnar's cards which I have successfully assigned using Lua (after pulling apart and attempting to understand user scripts posted here and the Linda scripts). I'd therefore prefer to use Lua for all the NGX buttons and I'd also really like to improve my Lua skills and will be very grateful if you could help me with this please? This is only a part of a much larger Lua script.

regards

Paul

Posted

I'd also really like to improve my Lua skills and will be very grateful if you could help me with this please? This is only a part of a much larger Lua script.

Okay. Let me get some one thing clearer then.

You are checking four buttons:

event.button(4, 23, "NGX_SHIFT")

event.button(4, 6, "NGX_NAV_INC")

event.button(4, 7, "NGX_NAV_DEC")

event.button(4, 30, "NGX_NAV_SEL")

I take it that only two of those are "action buttons" and the other two just modify that action. So, first question: are you thinking of pressing THREE buttons together, or do you want one or both of the modifying buttons to "toggle" between the two things they select from, on each press (i.e. FRACT<->WHOLE for NGX_SHIFT and NAV2<->NAV1 for NGX_NAV_SEL). It makes a difference how it is programmed.

P.S. I'm signing off for a few hours -- dinner and a TV break. Back later.

Regards

Pete

Posted

I'll be pressing 3 buttons together, NGX_SHIFT is a toggle switch and NGX_NAV_SEL is a pushbutton on a rotary encoder.

Shift 'off' and rotary encoder rotated will either increase or decrease whole on nav1

Shift 'off' and rotary encoder pressed in and rotated will increase or decrease fract on nav1

Shift 'on' + the above will do the same for nav2

I have a 2nd rotary encoder that will be used in a similar way for comm radios.

Hope this makes sense?

Enjoy your dinner and TV, I'm about to do the same!

regards

Paul

Posted
I'll be pressing 3 buttons together, NGX_SHIFT is a toggle switch and NGX_NAV_SEL is a pushbutton

Okay, so there's really only two active buttons. the other two are 'passive', so can simply be tested at the time, not using events and flags as you thought. So

function NGX_NAV_INC() -- dont need any parameters as you know this will be 4, 6, 1, as it is only called when pressed
if ipc.testbutton(4,23) then -- NGX_SHIFT is pressed
if ipc.testbutton(4, 30) then -- NGX_NAV_SEL is pressed
NGX_NAV2_FRACT_INC()
else --if NGX_SHIFT is pressed
NGX_NAV2_WHOLE_INC()
end
else
if ipc.testbutton(4, 30) then -- NGX_NAV_SEL is pressed
NGX_NAV1_FRACT_INC()
else
NAV1_WHOLE_INC()
end
end
end

function NGX_NAV_DEC() -- dont need any parameters as you know this will be 4, 7, 1, as it is only called when pressed
if ipc.testbutton(4,23) then -- NGX_SHIFT is pressed
if ipc.testbutton(4, 30) then -- NGX_NAV_SEL is pressed
NGX_NAV2_FRACT_DEC()
else --if NGX_SHIFT is pressed
NGX_NAV2_WHOLE_DEC()
end
else
if ipc.testbutton(4, 30) then -- NGX_NAV_SEL is pressed
NGX_NAV1_FRACT_DEC()
else
NAV1_WHOLE_DEC()
end
end
end

event.button(4, 6, "NGX_NAV_INC")
event.button(4, 7, "NGX_NAV_DEC")[/CODE]

Of course, this isn't as efficient as it could be. You are calling functions for the INC()'s and DEC()s even though they only contain one Lua statement in each. It would make it run faster by just replacing the function calls in the code above by the[b] ipc.control[/b] lines instead.

Okay? Do you see the logic now?

Regards

Pete

Posted

Thank you Pete, the logic certainly makes sense. I hadn't thought of using ipc.testbutton which does make it simpler.

Have a good weekend,

Paul

Posted

Thank you Pete, the logic certainly makes sense. I hadn't thought of using ipc.testbutton which does make it simpler.

And if you substitute the ipc.control() actions for the NGX...() function calls, even simpler / shorter. BTW I just fixed a typo -- "DECC" in last call to "DEC", and inserted two 'end' statements I omitted last night. (Things always look different in the morning! <G>).

Regards

Pete

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.