Board index FlightGear Development Nasal

Error reported on getprop with a variable as a parameter

Nasal is the scripting language of FlightGear.

Error reported on getprop with a variable as a parameter

Postby abassign » Sat May 26, 2018 10:25 pm

When a ballistic object is generated, in the sublayer "/ai/models" appears the node: /ai/models/model-added = "/ai[0]/models[0]/balistic[0]"
I need to extract the value of: "/ai[0]/models[0]/balistic[0]/name"
I try with this code:

Code: Select all
var getModelAdded = props.globals.getNode("/ai/models/model-added",1).getValue();
var getModelAdded_Name = props.globals.getNode(getModelAdded ~ "/name",1).getValue();


Not work the system return this error:
Code: Select all
Nasal runtime error: bad argument to setprop/getprop path: expected a string


Is there a way to avoid this error?
Last edited by abassign on Sun May 27, 2018 5:59 am, edited 1 time in total.
abassign
 
Posts: 725
Joined: Mon Feb 27, 2012 5:09 pm
Location: Italy (living 5 Km from airport LIME)
Callsign: I-BASSY
Version: 2018.3
OS: Linux Mint 19. x

Re: props.globals.getNode runtime error: bad argument

Postby Necolatis » Sat May 26, 2018 10:35 pm

That error does not seem to come from those lines of code. They are not getprop/setprop.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore


Hangar: https://sites.google.com/site/fghangar/
User avatar
Necolatis
 
Posts: 1859
Joined: Mon Oct 29, 2012 12:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2018.2.2
OS: Windows 10 Pro

Error reported on getprop with a variable as a parameter

Postby abassign » Sun May 27, 2018 5:01 am

Necolatis wrote in Sat May 26, 2018 10:35 pm:That error does not seem to come from those lines of code. They are not getprop/setprop.


I show you:

Image

In fact it seems like an error that comes from far away ... I copied the line of code to the position of line 229 (red line), and in that position it did not give me an error. I commented on the same line of code in position 251 (blue line) did not give me an error. I remove the comment on line 251 and report the error:

Code: Select all
Nasal runtime error: non-scalar in string context
  at /home/abassign/Dropbox/fgfs-Aircraft-custom/G91-R1B_HD/Nasal/Stores/Stores.nas, line 251
  called from: /home/abassign/fgfs/install/flightgear/fgdata/Nasal/globals.nas, line 119
Starting hard-coded terrain presampling


It seems an error related to setlistener, but I do not know how.
Last edited by abassign on Sun May 27, 2018 5:59 am, edited 1 time in total.
abassign
 
Posts: 725
Joined: Mon Feb 27, 2012 5:09 pm
Location: Italy (living 5 Km from airport LIME)
Callsign: I-BASSY
Version: 2018.3
OS: Linux Mint 19. x

Re: props.globals.getNode runtime error: bad argument

Postby Thorsten » Sun May 27, 2018 5:25 am

In red I inserted the references related to the error that I observe. As you can see it seems that "getprop" wants a string and not a variable that contains a string.


Getprop wants a string, yes. Why don't you just concatenate the two like

Code: Select all
getprop(getModelAdded~"/name");


as this forces an implicit type conversion, so whatever you had before the result is a string.
Thorsten
 
Posts: 9805
Joined: Mon Nov 02, 2009 8:33 am


Return to Nasal

Who is online

Users browsing this forum: No registered users and 2 guests