Jump to content
The simFlight Network Forums
Sign in to follow this  
tincan

Cam't write LVar in FSX

Recommended Posts

FSUIPC version 4972

 

Hi,

I am trying to write to a local variable in CaptainSim's C130 in fsx using a Lua file. There's a switch in the VC that I want to automate.

The FSUIPC log shows an error for this action:

ipc.writeLVar("L:pRpm1ButtonPos",dummy)
Quote

*** LUA Error: C:\FSX\Modules\c130.lua:113: attempt to call field 'writeLVar' (a nil value)

 

To make sure the variable exists I added a ReadLvar to the code.

C130.lua

109 	function rpmLow()
110	 		state=ipc.readLvar("L:pRpm1ButtonPos")
111 		ipc.display("RPM: "..state,1)
112 		dummy=1
113 		ipc.writeLVar("L:pRpm1ButtonPos",dummy)
114		end

141 	event.button("D", 5, 1, "rpmLow")

The read works, the result 1 or 0 is showing in the display window according to the position of the switch in the virtual cockpit. Log:

Quote

    71839 LUA.0: Button event: calling "rpmLow" in "C:\FSX\Modules\c130.lua"
    71839 LUA.0: C:\FSX\Modules\c130.lua:110
    71839 LUA.0: C:\FSX\Modules\c130.lua:111
    71839 LUA.0: Global: state = 1
    71870 LUA.0: C:\FSX\Modules\c130.lua:112
    71870 LUA.0: C:\FSX\Modules\c130.lua:113
    71870 *** LUA Error: C:\FSX\Modules\c130.lua:113: attempt to call field 'writeLVar' (a nil value)
    71870 LUA.0: Waiting for an event in "C:\FSX\Modules\c130.lua"

I don't understand what the "nil value' means here. How can I fix this?  Thanks.

 

 

Share this post


Link to post
Share on other sites
7 hours ago, tincan said:

The read works

Because you spelled the read function name correctly. Compare it to your write one. you have too many capital letters. Luke did suggest you check!  You could also compare it to the one in the manual.

Quote

I don't understand what the "nil value' means here.

"nil" is "no value" (basic Lua) , meaning in this case, as it says, writeLVar (a nil value) cannot be executed (because it doesn't exist).

Quote

Yes, you can see in the log that the code is executed.

No, the code fails. That is why an error is reported. And the error report is quite specific, it tells you exactly what is wrong

Unfortunately, like C/C++ (but unlike some languages), Lua is very case sensitive. I have tried to include some cases of different capitalisations, but i couldn't add them all without making the lookup tables very long!

Pete

 

Share this post


Link to post
Share on other sites
17 hours ago, Luke Kolin said:

Do you have the function name capitalized properly?

Cheers!

Tunnel vision. I thought you meant my own function`s name.

 

Quote

And the error report is quite specific, it tells you exactly what is wrong

Well, I'd argue that but to no point. Thanks for spotting this guys! Clear skies. 

Share this post


Link to post
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...
Sign in to follow this  

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