Board index FlightGear Development Nasal

nil in numeric context??  Topic is solved

Nasal is the scripting language of FlightGear.

nil in numeric context??

Postby wkitty42 » Wed Jul 20, 2016 8:08 pm

what does this mean?
Code: Select all
Nasal runtime error: nil used in numeric context

the line pointed to is
Code: Select all
var wpt= wp.getvalue() -1;
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9161
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 22.04

Re: nil in numeric context??

Postby D-ECHO » Wed Jul 20, 2016 8:18 pm

I think it means that the value used is not a number :D
D-ECHO
 
Posts: 2462
Joined: Sat May 09, 2015 1:31 pm
Pronouns: Bea (she/her)
Version: next

Re: nil in numeric context??

Postby PINTO » Wed Jul 20, 2016 8:20 pm

It means wp.getValue() is evaluating to nil, and the nasal interpreter won't do arithmetic on nil values. You can throw an if-statement right before the line checking if it's nil or not. Something like
Code: Select all
if ( wp.getValue() == nil ) {
   var wpt = -1; # or whatever default value you want
} else {
  var wpt = wp.getValue() - 1;
}
Actively developing the MiG-21bis (github repo) (forum thread) (dev discord) (fg wiki)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 966
Joined: Wed Oct 21, 2015 7:28 pm
Callsign: pinto
Version: stable
OS: Win10

Re: nil in numeric context??

Postby wkitty42 » Wed Jul 20, 2016 9:00 pm

interesting... now that i look at these two comments, i didn't think about the "-1" being "minus one"... i saw it as "negative one" but couldn't understand why it would be there... i'll give the "if" statement a try and see how it goes...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9161
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 22.04

Re: nil in numeric context??

Postby Hooray » Wed Jul 20, 2016 9:42 pm

it is referring to the lvalue, the rvalue is the numerical concept - and the lvalue evaluates to a non-numerical nil value, which means that the expression as a whole cannot be evaluated
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: nil in numeric context??

Postby wkitty42 » Wed Jul 20, 2016 10:35 pm

well, i don't get that error any more when the sim starts up... i'm not sure if the value is right but at least there's no error and a property being set seems to be changed as the item is triggered...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9161
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 22.04

Re: nil in numeric context??  

Postby Thorsten » Thu Jul 21, 2016 7:42 am

It's about wp.getvalue().

Say that function looks like

Code: Select all
wp.getvalue = func {

var string =  "No value found";

return string;
}


so then the function evaluates fine, but then

Code: Select all
var wpt= wp.getvalue() -1;


tries to do "No value found" -1 - which doesn't work. Same if the function never assigns any value to the return - then it evaluates to NIL and Nasal can't subtract one from that either.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: nil in numeric context??

Postby wkitty42 » Thu Jul 21, 2016 5:52 pm

yeah, i have no idea where wp.getValue is created... the error i was seeing was in a craft's systems.nas file... assuming that it is a nasal script that creates it, i don't find it in fgdata, either, so i can't look closer to see why it may be nil... i do know that it is a capital 'V' in "Value", though... i did make that mistake ;)
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9161
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 22.04

Re: nil in numeric context??

Postby Hooray » Thu Jul 21, 2016 7:51 pm

It's more like a navdb-related FGPositioned data structure / API (see the navcache article)
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: nil in numeric context??

Postby PINTO » Thu Jul 21, 2016 8:23 pm

It's route manager related, actually. To find the correct member of the route/wp[] vector that the current-waypoint property is pointing to. This line of code is very common in system.nas in multiple airplanes.
Actively developing the MiG-21bis (github repo) (forum thread) (dev discord) (fg wiki)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 966
Joined: Wed Oct 21, 2015 7:28 pm
Callsign: pinto
Version: stable
OS: Win10

Re: nil in numeric context??

Postby Hooray » Thu Jul 21, 2016 9:19 pm

FYI: The route manager is indeed handling/returning FGPositioned objects (so called Nasal ghosts wrapping FGPositioned smart pointers)
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU


Return to Nasal

Who is online

Users browsing this forum: No registered users and 3 guests