tegwin
(Tegwin)
March 21, 2023, 10:32am
1
I am attempting to use some of the GPS tags in LUA
I am using plane 4.3.4 on cube orange
If I try either of these I get an error - “number expected, got nil ”
Mission planner says 11 sats so I would expect that function to return 11 instead of nil.
gcs:send_text(0, gps:num_sats(instance))
gcs:send_text(0, gps:time_week_ms( instance ))
Is there a bug with these or am I totally missing something needed to make them work?
Yuri_Rage
(Yuri Rage)
March 21, 2023, 12:50pm
2
What value is instance
assigned? In most cases, it should be zero.
Also, if you are running that script immediately upon boot, the GPS may not be initialized before you reference it.
tegwin
(Tegwin)
March 21, 2023, 1:55pm
3
If I assign it 0 or gps:primary_sensor() it was not working.
Turns out the return is an integer. It now works if I use tostring() … Every day is a school day!
This works:
local sat_time = tostring(gps:time_week_ms( 0 ))
gcs:send_text (0, sat_time)
2 Likes
Yuri_Rage
(Yuri Rage)
March 21, 2023, 2:07pm
4
Indeed, Lua is not strictly typed, but your scripts will be less frustrating if you treat it as if it is, where practical.