0

Whenever I try to run my Lua script, right after the first function, be it defining a parameter, mission planner (ground control station of ardupilot), display an error message saying unexpected token.

function pr()
local altitude = vehicle:get_altitude()
  if altitude > 1 
  then
    abc:set_value(1)
    gcs:send_text("Above 1m")
  else
    abc:set_value(0)
    gcs:send_text("Below 1m")
  end

return update, 500 end

local abc = param:define_class("abc") abc:set_name("test") abc:set_description("This is a test parameter.") abc:set_value(1)

param:add_parameter(abc) pr()

Here, right after the function, it displays an error message:

("SyntaxError: unexpected token 'abc'")

liggiorgio
  • 4,636
  • 6
  • 25
  • 37

1 Answers1

0

abc is shown in the pr() function before it is defined. This is likely because you're defining abc as a local variable.

Some suggestions to fix it:

  • make abc a global variable by removing the local part. (I recall pico-8 auto defines variables that way)
  • add the abc as parameter to the pr() function , like pr(abc) at both locations
Steven
  • 891
  • 6
  • 19