Jump to content
The simFlight Network Forums

Lua event.button syntax

Recommended Posts

Hello all -

P3D v4.2 Fsuipc 5.124 Registered
FSUIPC5.Joyscan.csv see file attached
Fsuipc.ini file attached
Log file attached

I am trying to get my head round Lua functions. To that end I have written a simple chunk to use to understand them, cribbing from the FSUIPC Lua Library I came up with this saved as AA_Function.lua in the modules directory of P3D

1-- ## Altitude Alert ##########  
4    function ALT_alert_plus(3, 11, 1)  -- joynum, button, downup
6        AAvalue = ipc.readLvar("Alt_alert_setting")
7        ipc.writeLvar("Alt_alert_setting", AAvalue+100)
9    end
11    event.button(3,11,"ALT_alert_plus")

When called directly from an assigned button (3,11) this fails with the error:
422294 *** LUA Error: D:\P3D\Prepar3D v4\Modules\AA_Function.lua:4: <name> or '...' expected near '3'

For reference the Library states:

Your processing function:
function-name(joynum, button,downup)

event.button(joynum, button,“function-name”)

Clearly I am not understanding the syntax requirements and/or other function processes - could someone please enlighten me or point to a tutorial?

Looking ahead I will want to run this chunk on a different button/rotary over WideFS The red warning in the event.button library entry indicates this is not possible, on the other hand the associated text indicates the joystick will be seen over widefs. Could you please clear up any misunderstandings I have.

Many thanks for any response
Kind regards
Gordon Hurn




Link to comment
Share on other sites

5 minutes ago, Hoveruser said:

function ALT_alert_plus(3, 11, 1)  -- joynum, button, downup

The function definition RECEIVES values, but you have pre-defined values instead.

The event.button function, as you say, is defined as having a definition of

function-name(joynum, button,downup)

which means it has three parameters provided: the joystick number, the button number, and whether the button in down or up. YOU do not pre-defined these, those parameters are filled in for you. If you want them you give them names and refer to those names in the code which follows.

This is the way functions are in every language I know of. In the above case, your one function could actually, if you wished, be called by defined events for any number of other buttons.

BTW: Really, for help with the Lua language specifically you should visit the Lua website, as pointed to in my Lua facilities documentation. I am not the really person to teach basic programming (I am a really lousy teacher! ;-) )..



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.