Board index FlightGear Development Nasal

help - nasal runtime error

Nasal is the scripting language of FlightGear.

help - nasal runtime error

Postby gkick » Sun Jun 23, 2019 6:32 am

Hi,

running code to fetch atis for destination airport and set comm1 accordingly. Works usually well however at times I end up with this:

non objects have no members nasal error
line 838

the code is

Code: Select all
#Fetch atis if route-manager destination ap changes

setlistener("/autopilot/route-manager/destination/airport", func {
   if (getprop("/autopilot/route-manager/destination/airport") != nil ) {         
      if (getprop("/systems/eap")==1) {      
var airport = airportinfo(getprop("autopilot/route-manager/destination/airport"));
var atis = airport.comms('atis');
if (!size(atis))
    atis = airport.comms('awos');
if (size(atis)== 0){
      print ("no atis data found, comm1 set to 111.1");         
      setprop("/instrumentation/comm/frequencies/selected-mhz", 111.11);
      } else {   
   setprop("/systems/catis",atis[0]);
   setprop("/instrumentation/comm/frequencies/selected-mhz", (getprop("/systems/catis")));   
}
}   
}});


funny enough comm1 is set to the correct frequency. Could not find an error description in the nasal error wiki

thanks
gkick
 
Posts: 106
Joined: Mon Jan 02, 2017 12:04 am

Re: help - nasal runtime error

Postby legoboyvdlp » Sun Jun 23, 2019 9:25 am

If you could tell us which line is 838 that would help a lot to diagnose it.
User avatar
legoboyvdlp
 
Posts: 7981
Joined: Sat Jul 26, 2014 2:28 am
Location: Northern Ireland
Callsign: G-LEGO
Version: next
OS: Windows 10 HP

Re: help - nasal runtime error

Postby Thorsten » Sun Jun 23, 2019 9:26 am

The error occurs whenever you have a

Code: Select all
object.member = X


or

Code: Select all
object.member()


structure when object is not defined as a hash, i.e.

Code: Select all
object = {};


has not been explicitly or implicitly been done.

In your code snippet (of which we unfortunately do not know the line numbers, so the line 838 is not really helpful...) the likely candidate is airport which becomes a hash implicitly by getting the result of airportinfo assigned - assuming that fails and returns NIL, the rest would fail with the above error.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: help - nasal runtime error

Postby gkick » Mon Jun 24, 2019 4:08 am

Thanks guys,

line 838 is the var atis = airport.comms('atis');

I have the same code to set the com1 frequency if the sim/presets/airport changes and it does not trigger that message, maybe something to do with the route manager?
gkick
 
Posts: 106
Joined: Mon Jan 02, 2017 12:04 am

Re: help - nasal runtime error

Postby Thorsten » Mon Jun 24, 2019 6:21 am

Well, it would appear that airportinfo returned NIL for some reason, but the why I can't guess.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: help - nasal runtime error

Postby legoboyvdlp » Mon Jun 24, 2019 9:48 am

Well - a quick guess, are you absolutely sure the route manager is set? This would be a case where you want to make a nil check:

if destination != nil {
present line 838
}

That will ensure your code always works ;)

If that isn't the issue I also have no idea what it would be.
User avatar
legoboyvdlp
 
Posts: 7981
Joined: Sat Jul 26, 2014 2:28 am
Location: Northern Ireland
Callsign: G-LEGO
Version: next
OS: Windows 10 HP

Re: help - nasal runtime error

Postby gkick » Mon Jun 24, 2019 4:55 pm

Thanks but noops.
gkick
 
Posts: 106
Joined: Mon Jan 02, 2017 12:04 am


Return to Nasal

Who is online

Users browsing this forum: No registered users and 2 guests