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 11: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 6:59 am, edited 1 time in total.
Developer of the program https://wiki.flightgear.org/Julia_photoscenery_generator
FDM developer of the G91R1B aircraft https://wiki.flightgear.org/FIAT_G91R1B
JSBSim collaborator
abassign
 
Posts: 947
Joined: Mon Feb 27, 2012 6:09 pm
Location: Italy (living 5 Km from airport LIME)
Callsign: I-BASSY
Version: 2020.4
OS: Ubuntu 20.10

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

Postby Necolatis » Sat May 26, 2018 11: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
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Error reported on getprop with a variable as a parameter

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

Necolatis wrote in Sat May 26, 2018 11: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 6:59 am, edited 1 time in total.
Developer of the program https://wiki.flightgear.org/Julia_photoscenery_generator
FDM developer of the G91R1B aircraft https://wiki.flightgear.org/FIAT_G91R1B
JSBSim collaborator
abassign
 
Posts: 947
Joined: Mon Feb 27, 2012 6:09 pm
Location: Italy (living 5 Km from airport LIME)
Callsign: I-BASSY
Version: 2020.4
OS: Ubuntu 20.10

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

Postby Thorsten » Sun May 27, 2018 6: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: 12490
Joined: Mon Nov 02, 2009 9:33 am


Return to Nasal

Who is online

Users browsing this forum: No registered users and 3 guests