Jump to content
The simFlight Network Forums

Lua/FSUIPC - attempt to index global 'event' (a nil value)


Recommended Posts

Although I have had experience with many program languages over many years, I am new to Lua (and FSUIPC for that matter), but am rapidly becoming very frustrated. Yesterday morning I was able to run the following simple Lua script without error and assign a joystick button (via FSUIPC) to call it and it worked.


joy = 0
btn = 18
function TogglePitotHeat(j, b, du)
-- Cancel event so we don't get called again for double press
event.cancel("TogglePitotHeat")
value = ipc.readUB(0x029C)
if value == 1 then
ipc.writeUB(0x029C,0)
else
ipc.writeUB(0x029C,1)
end
end
event.button(joy, btn, 1, "TogglePitotHeat")
[/CODE]

However, I now keep getting the following error (which always gives the line the 'event.button' statement is on):

[CODE]
>lua -e "io.stdout:setvbuf 'no'" "TogglePitotHeat.Lua"
lua: TogglePitotHeat.Lua:16: attempt to index global 'event' (a nil value)
stack traceback:
TogglePitotHeat.Lua:16: in main chunk
[C]: ?
>Exit code: 1
[/CODE]

I have tried to search for help on this (both on internet and this forum), but although some results with similar symptoms were available, it seemed mainly due to coding errors. However, I even tried with the following code (as well as using the code from one of the FSUIPC example scripts) and get same result.

[CODE]
function setXpndr(J,b,du)
-- do nothing
end
event.button(0,18,1,"setXpndr")
[/CODE]

It appears there is a link between Lua and FSUIPC missing and Lua cannot see the event library, but am unable to determine where to correct this. I have even un-installed and re-installed Lua (for Windows v5.1.4-46) to see if this would rectify the problem but no success.

I realise this may need to be put on the Lua forums, but I am hoping someone here has come across the fix for this.

Can anyone help (please!) as I am getting very frustrated!

Dave

Link to comment
Share on other sites

Having spent the last couple of days trying to fix this...

reinstalled LUA4Win/SciTE (more than once)

reinstalled MS C++ runtimes (saw a thread where this help in similar case)

reinstalled FSUIPC4

disabled/enabled firewall

set environment path variables for LUA4Win/SciTE to point to \Modules directory

and much more...

Even thought about installing the whole shebang (i.e. FSX/FSUIPC/Lua, etc) on old XP PC to see if it was a Win 7 (64-bit) issue.

However now my I/O card has arrived I need to move on (life is too short) so have given up trying to fix this problem!

Instead although still using SciTE to edit the Lua scripts, I am now using ipc.log statements to debug via FSUIPC.

So now looking to create a radio stack controller using BU0836X card and Lua scripts...

Phase 1: Xponder - set xpondr code using 10 (i.e. 0-9) push buttons arranged in keypad format.

Phase 2: COM1/COM2 - set frequencies using dual rotary encoder to set frequency integer/decimal

Phase 3: NAV1/NAV2 - as above, etc...

Dave

Link to comment
Share on other sites

However, I now keep getting the following error (which always gives the line the 'event.button' statement is on):


>lua -e "io.stdout:setvbuf 'no'" "TogglePitotHeat.Lua"
lua: TogglePitotHeat.Lua:16: attempt to index global 'event' (a nil value)
stack traceback:
TogglePitotHeat.Lua:16: in main chunk
[C]: ?
>Exit code: 1
[/CODE]

If you execute a Lua program externally to FSUIPC, as you seem to be doing here, and it tries calling built-in FSUIPC libraries such as event and ipc, then naturally you will get this error. The libraries added by FSUIPC are specific to FSUIPC and its interface into FS. They are NOT part of the standard Lua library package!

It appears there is a link between Lua and FSUIPC missing and Lua cannot see the event library, but am unable to determine where to correct this. I have even un-installed and re-installed Lua (for Windows v5.1.4-46) to see if this would rectify the problem but no success.

FSUIPC Lua libraries are internal to FSUIPC and the FS process. You cannot access them from a completely separate process in a completely separate virtual machine!

Pete

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • 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.