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 5: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: Sun Jan 01, 2017 11:04 pm

Re: help - nasal runtime error

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

If you could tell us which line is 838 that would help a lot to diagnose it.
User avatar
legoboyvdlp
 
Posts: 6849
Joined: Sat Jul 26, 2014 1:28 am
Callsign: YV-LEGO
Version: 2018.3.1
OS: Windows 10 HP

Re: help - nasal runtime error

Postby Thorsten » Sun Jun 23, 2019 8: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: 10693
Joined: Mon Nov 02, 2009 8:33 am

Re: help - nasal runtime error

Postby gkick » Mon Jun 24, 2019 3: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: Sun Jan 01, 2017 11:04 pm

Re: help - nasal runtime error

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

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

Re: help - nasal runtime error

Postby legoboyvdlp » Mon Jun 24, 2019 8: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: 6849
Joined: Sat Jul 26, 2014 1:28 am
Callsign: YV-LEGO
Version: 2018.3.1
OS: Windows 10 HP

Re: help - nasal runtime error

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

Thanks but noops.
gkick
 
Posts: 106
Joined: Sun Jan 01, 2017 11:04 pm


Return to Nasal

Who is online

Users browsing this forum: No registered users and 1 guest