Board index FlightGear Development Nasal

getprop error message

Nasal is the scripting language of FlightGear.

getprop error message

Postby Autowings » Thu Oct 31, 2019 9:01 am

Hi everyone,

To create a flight parameter browser with selectable inputs, I try to retrieve a property value from a property listed in another property. The property "/autopilot/external/bank/input" has been set in the aircraft_set.xml and contains the property path string "/autopilot/internal/heading-bug-error-deg". Both strings are valid property paths.

Code: Select all
var path = '/autopilot/external/bank/';
var propinput = getprop(path ~ "input");
print(propinput);
input = getprop("/autopilot/internal/heading-bug-error-deg");
print(input);
input = getprop(propinput);
print(input);


This piece of code is not bound to a specific aircraft model or properties but can be reproduced with any property string.

When executing this code, I get an error message at line #6:
'"' found in propertyname after '''. name must begin with alpha or '_'.

It seems to be impossible to retrieve a property value by a string that itself is a result of getprop() or node.getNode().getValue().

The property path string inside propinput is correct. When I call getprop() with this string manually inserted, I get the desired output (see lines ##4 and 5).
I've tried several things to get rid of this problem, but without success.

What am I doing wrong or what can I do to make it work?

Thanks in advance,
Autowings
Autowings
 
Posts: 6
Joined: Thu Oct 31, 2019 8:09 am

Re: getprop error message

Postby Thorsten » Thu Oct 31, 2019 9:04 am

Your first line uses ' as quotation marks, later you use " - that'd be the first thing to try.
Thorsten
 
Posts: 11327
Joined: Mon Nov 02, 2009 8:33 am

Re: getprop error message

Postby Autowings » Thu Oct 31, 2019 9:53 am

Hi Thorsten,

Thank you for your quick reply.

I changed the ' to ", but the result is still the same.

Code: Select all
var path = "/autopilot/external/bank/";
var propinput = getprop(path ~ "input");
print(propinput);
input = getprop("/autopilot/internal/heading-bug-error-deg");
print(input);
input = getprop(propinput);
print(input);
Autowings
 
Posts: 6
Joined: Thu Oct 31, 2019 8:09 am

Re: getprop error message

Postby F-TLS13 » Thu Oct 31, 2019 9:56 am

What is the type of the propinput variable?
Maybe print is able to cast it as a string, and getprop expects a string and gets... Something else?

Edit: I do not know nasal, just my two cents coming from strongly typed languages
F-TLS13
 
Posts: 7
Joined: Thu Jul 25, 2019 4:18 pm
Callsign: F-TLS13
Version: 2019.2
OS: Fedora 31

Re: getprop error message

Postby Thorsten » Thu Oct 31, 2019 10:04 am

It seems to be impossible to retrieve a property value by a string that itself is a result of getprop() or node.getNode().getValue().


No, I've just tried a short Nasal script and it works just as expected - so there's probably something odd with your pre-existing properties rather than the script (which looks otherwise okay to me). For some reason they're not returning a string.
Thorsten
 
Posts: 11327
Joined: Mon Nov 02, 2009 8:33 am

Re: getprop error message

Postby Autowings » Thu Oct 31, 2019 10:49 am

I created the propinput in the aircraft_set.xml as follows:

Code: Select all
    <external>
      <bank>
         <input type="string">"/autopilot/internal/heading-bug-error-deg"</input>
      </bank>
    </external>


The property browser shows it with the suffix (string). So it should definitely be a string.

Because I'm coming from the C/C++ world, I thought that strings should always be quoted by " or '. :oops:
I removed the quotation marks from the xml declaration, and now it works. :D

Code: Select all
    <external>
      <bank>
         <input type="string">/autopilot/internal/heading-bug-error-deg</input>
      </bank>
    </external>


Thank you for your help!
Autowings
 
Posts: 6
Joined: Thu Oct 31, 2019 8:09 am


Return to Nasal

Who is online

Users browsing this forum: No registered users and 1 guest