betaflight-tx-lua-scripts icon indicating copy to clipboard operation
betaflight-tx-lua-scripts copied to clipboard

Syntax error background.lua line 12

Open RadianceNL opened this issue 9 years ago • 33 comments

With the new 1.0 lua scripts I get a syntax error in backgrounds.lua on line 12, attempt to index a nil vallue.

I'm own a X7 and the previous version 0.3 is working just fine.

Any ideas?

RadianceNL avatar Nov 18 '17 17:11 RadianceNL

@codecae: Looks like a guard is needed for the case that getFieldInfo(protocol.stateSensor) returns nil.

mikeller avatar Nov 18 '17 20:11 mikeller

It is hardcoded to both protocols. Not sure why this would occur. Perhaps @RadianceNL has an older version of protocols.lua.

codecae avatar Nov 18 '17 21:11 codecae

I was more thinking of the getFieldInfo() call returning nil for whatever reason. But it could be caused by an older version of OpenTx. Is there a way to detect the OpenTx version in lua? If so, we should probably add a warning for users trying to run on an old version.

mikeller avatar Nov 18 '17 21:11 mikeller

Perhaps a getVersion() fast fail as part of radios.lua is in order.

codecae avatar Nov 18 '17 21:11 codecae

Here https://github.com/betaflight/betaflight-tx-lua-scripts/blob/master/src/SCRIPTS/BF/radios.lua#L38

codecae avatar Nov 18 '17 21:11 codecae

Forgot to mention that I am running OpenTX 2.2.0 and as far as I know that is the latest version?

I've downloaded 1.0 from the release page and installed no heli, lua and multi module firmware version through the companion app.

RadianceNL avatar Nov 18 '17 21:11 RadianceNL

It should work fine with 2.2 .. can you try deleting the scripts from your SD and recopy them?

On Sat, Nov 18, 2017, 4:24 PM RadianceNL [email protected] wrote:

Forgot to mention that I am running OpenTX 2.2.0 and as far as I know that is the latest version?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/betaflight/betaflight-tx-lua-scripts/issues/90#issuecomment-345472382, or mute the thread https://github.com/notifications/unsubscribe-auth/AHyTqXKTgxS8XjKN8RiY6kdzVfMfVR98ks5s30sUgaJpZM4QjFhD .

codecae avatar Nov 18 '17 21:11 codecae

Sure I will but I've already done that actually this afternoon. I will redownload the scripts and try again.

Edit: Recopied the files and still have the same error.

RadianceNL avatar Nov 18 '17 21:11 RadianceNL

Try rediscovering sensors

codecae avatar Nov 18 '17 21:11 codecae

Already done that as well, delete all sensors and then discover them again but didn't do the trick.

I use a R XSR btw with the latest FCC firmware.

RadianceNL avatar Nov 18 '17 21:11 RadianceNL

@mikeller it looks like in the v1.0 zip that the return is on line 12. This should be fixed in master, right?

codecae avatar Nov 18 '17 22:11 codecae

When I select the script I see bf, so no capital letters like the previous version had.

On my SD card I have bf.lua as well, not BF.lua

RadianceNL avatar Nov 18 '17 22:11 RadianceNL

Do you have a Tmp1 sensor in your list of telemetry sensors?

codecae avatar Nov 18 '17 22:11 codecae

Yes, it's reading 10011 to 30011 degrees celsius.

When I didn't had telementry I was able to start up the lua script but once telementry got recovered I get syntax error BF/MSP/common.lua line 107.

Attempt to perform arit.....

RadianceNL avatar Nov 18 '17 22:11 RadianceNL

And after another reboot of the transmitter everything started to work...very strange but thanks a lot for the help.

Although I'm curious what happend

RadianceNL avatar Nov 18 '17 22:11 RadianceNL

@codecae:

it looks like in the v1.0 zip that the return is on line 12. This should be fixed in master, right?

Looking at the zip, background.lua is:

mikeller@pc:~/tmp$ cat -n obj/SCRIPTS/BF/background.lua | head -20
     1	local INTERVAL          = 50         -- in 1/100th seconds
     2	local MSP_SET_RTC       = 246
     3	local MSP_TX_INFO       = 186
     4	
     5	local lastRunTS
     6	local sensorId = -1
     7	local timeIsSet = false
     8	local mspMsgQueued = false
     9	
    10	local function getSensorValue()
    11	    if sensorId == -1 then
    12	        sensorId = getFieldInfo(protocol.stateSensor)['id'] or -1
    13	    end
    14	    return getValue(sensorId)
    15	end
    16	
    17	local function modelActive(sensorValue)
    18	    return type(sensorValue) == "number" and sensorValue > 0
    19	end
    20	

To me it looks like there is something dodgy with sensor discovery, and that causes getFieldInfo() to return nil in some cases.

My hunch would be to leave it as it is for now (or do a quick fix fending against the nil return), and then rewrite the whole polling once betaflight/betaflight#4611 is in, and make it use MSP to query the status of RTC and RSSI, and act accordingly.

mikeller avatar Nov 18 '17 22:11 mikeller

Miscounted the lines on my phone.. my bad :)

codecae avatar Nov 18 '17 23:11 codecae

Yes, doesn't work for me either, I get the nil return from line 12 on background.lua as well

alejoal07 avatar Nov 19 '17 07:11 alejoal07

Here also. Just installed v1.0 and same error..

estella17 avatar Nov 20 '17 00:11 estella17

I'm getting nil return on line 12 also on a qx-7 and r-xsr with version 1. Running opentx2.2 newest release, internal module updated and the r-xsr. I have to turn off receiver to recover telemetry screen. But when it does work, it will change pids.

knockoutperformance avatar Nov 20 '17 12:11 knockoutperformance