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 8: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: 269
Joined: Fri May 19, 2017 8:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: next
OS: Ubuntu 18.04.4

Re: Create a new property ?

Postby AndersG » Tue Jun 20, 2017 8: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: 2525
Joined: Wed Nov 29, 2006 10:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: Create a new property ?

Postby rleibner » Wed Jun 21, 2017 2: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: 269
Joined: Fri May 19, 2017 8:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: next
OS: Ubuntu 18.04.4

Re: Create a new property ?

Postby rleibner » Thu Jun 22, 2017 2: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: 269
Joined: Fri May 19, 2017 8:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: next
OS: Ubuntu 18.04.4

Re: Create a new property ?  

Postby Octal450 » Thu Jun 22, 2017 2:50 am

Yes
You can put him in the -set file, and he will be defined.
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
Last edited by Octal450 on Thu Feb 15, 2024 8:33 am, edited 1 time in total.
Skillset: JSBsim Flight Dynamics, Systems, Canvas, Autoflight/Control, Instrumentation, Animations
Aircraft: A320-family, MD-11, MD-80, Contribs in a few others

Octal450's GitHub|Launcher Catalog
|Airbus Dev Discord|Octal450 Hangar Dev Discord
User avatar
Octal450
 
Posts: 5583
Joined: Tue Oct 06, 2015 1:51 pm
Location: Huntsville, AL
Callsign: WTF411
Version: next
OS: Windows 11

Re: Create a new property ?

Postby arghyanir.giri » Mon Sep 07, 2020 7:50 pm

Can we create a new property from model.xml file?
arghyanir.giri
 
Posts: 9
Joined: Wed Aug 19, 2020 4:30 pm

Re: Create a new property ?

Postby SE-HK » Sun Sep 13, 2020 3:06 pm

arghyanir.girl, do you mean some special file?
Perhaps I misunderstand, but you can create a custom xml file and load it during start using
Code (): Select all
--config=myfile.xml
and it can have a content like
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<PropertyList>
   <my-path>
      <my-prop>0</my-prop>
   </my-path>
</PropertyList>
SE-HK
 
Posts: 54
Joined: Wed Sep 02, 2009 2:16 pm
Location: Stockholm, Sweden
Version: git
OS: Ubuntu 20.04

Re: Create a new property ?

Postby Hooray » Sun Sep 13, 2020 4:12 pm

non-existing properties that are referenced by an PropertyList/XML file are usually created automatically, even though there are some corner cases - e.g. tied properties or those conceptually owned by a dedicated subsystem.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Create a new property ?

Postby SE-HK » Mon Sep 14, 2020 3:35 am

As Hooray says, properties are created automatically. However, it can be useful to explicitly set the type, ie
Code (): Select all
<my-prop type="bool">0</my-prop>
SE-HK
 
Posts: 54
Joined: Wed Sep 02, 2009 2:16 pm
Location: Stockholm, Sweden
Version: git
OS: Ubuntu 20.04


Return to Nasal

Who is online

Users browsing this forum: No registered users and 2 guests