Board index FlightGear Development Nasal

Create a new property ?  Topic is solved

Nasal is the scripting language of FlightGear.

Create a new property ?

Postby rleibner » Tue Jun 20, 2017 7:22 pm

Hi guys,
In my .nas code (which will be called more than once by the pilot) I must "log" a value. The idea is to check whether I was there or not in the same FG session.
I tryed with
Code: Select all
setprop("/instrumentation/comm/my-prop", 0,0);
but it not works :(

Is there a way to do that? Is too much dirty to use an existing wilcard property?
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 222
Joined: Fri May 19, 2017 7:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: 2180.3.0
OS: Ubuntu 17.10

Re: Create a new property ?

Postby AndersG » Tue Jun 20, 2017 7:35 pm

Did you try
Code: Select all
setprop("/instrumentation/comm/my-prop", 0.0);

?

It ought to work.

You can also use
Code: Select all
props.globals.initNode("/instrumentation/comm/my-prop", 0.0, "DOUBLE");

to create the property with a given default value if it doesn't exist already.
(See Nasal/props.nas for the available Node "instance methods".)
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2413
Joined: Wed Nov 29, 2006 9:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: Create a new property ?

Postby rleibner » Wed Jun 21, 2017 1:12 pm

You are right, Anders.
In fact, the simple setprop does work !
Debugging the code, I confused myself and blamed that line, but the problem was elsewhere. :oops:
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 222
Joined: Fri May 19, 2017 7:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: 2180.3.0
OS: Ubuntu 17.10

Re: Create a new property ?

Postby rleibner » Thu Jun 22, 2017 1:32 am

Let me clarify the question:

Can a new property be created at the beginning of each session?
I mean, Without binding any key or button.
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 222
Joined: Fri May 19, 2017 7:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: 2180.3.0
OS: Ubuntu 17.10

Re: Create a new property ?  

Postby it0uchpods » Thu Jun 22, 2017 1:50 am

Yes
You can put him in the -set file, and he will be defined. See my A320: https://github.com/it0uchpods/A320Famil ... AE-set.xml
Line 124-128, this declares the options "folder" in the PropertyTree, then adds the properties EIS2, eng, and maxblock with that default value.

For the setprop, this will work: setprop("/something/my-property", 'HELLO!"); will set /something/my-property to "HELLO!"

If you are using INTs, or DOUBLEs, you can just put the numbers without the quotes: setprop("/something/my-number-property", 411); will set /something/my-number-property to 411.

Kind Regards,
Josh
it0uchpods/WTF411

FGFS Aircraft Developer
Lead Programmer at it0uchpods Design Group
Download High Quality Aircraft from it0uchpods Hangar
User avatar
it0uchpods
 
Posts: 3456
Joined: Tue Oct 06, 2015 12:51 pm
Version: 2018.2.1
OS: Windows 10 x64


Return to Nasal

Who is online

Users browsing this forum: No registered users and 2 guests