Board index FlightGear Development

Read/Write from files via Nasal

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

Re: Read/Write from files via Nasal

Postby jam007 » Sun May 21, 2017 4:28 pm

jam007
 
Posts: 579
Joined: Sun Dec 16, 2012 11:04 am
Location: Uppsala, Sweden
Callsign: LOOP
Version: 2020.4.0
OS: Ubuntu 22.04

Re: Read/Write from files via Nasal

Postby Thorsten » Sun May 21, 2017 5:51 pm

I can't write in the aircraft's own folder?


Of course you can't, because FG may be installed system-wide whereas you are sitting at your user account, so naturally Nasal may not assume write-permissions into the aircraft folder.

The only place where Nasal can write has to be inside your own user directory - you can write parts of $FGHome but definitely not $FGAircraft, $FGData or $FGScenery, and since Nasal is generally not secure (I can send you all sorts of Nasal scripts hidden in a 3rd party aircraft) what Nasal is allowed to do is even more restricted.

I'm not sure you would enjoy an aircraft which installs scripts to send me your credit card number...
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Read/Write from files via Nasal

Postby Octal450 » Tue May 23, 2017 2:27 pm

OK. So $FGHome/FlightGear/A320Family/settings.conf

Would work?

I get the security risk now. I would like to see some of these scripts out of curiosity, if you don't mind.

J
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: Read/Write from files via Nasal

Postby sanhozay » Tue May 23, 2017 2:40 pm

it0uchpods wrote in Tue May 23, 2017 2:27 pm:OK. So $FGHome/FlightGear/A320Family/settings.conf

Just checking that you aren't trying to reinvent the wheel here ...

You do know about making properties persistent using the aircraft-data tag in the -set.xml file and the existence of the aircraft.data.add library function?

Persistent Properties

This just creates XML files under $FG_HOME/aircraft-data, that you can edit outside of Flightgear.
sanhozay
 
Posts: 1207
Joined: Thu Dec 26, 2013 12:57 pm
Location: EGNM
Callsign: G-SHOZ
Version: Git
OS: Ubuntu 16.04

Re: Read/Write from files via Nasal

Postby Johan G » Tue May 23, 2017 8:52 pm

sanhozay wrote in Tue May 23, 2017 2:40 pm:Just checking that you aren't trying to reinvent the wheel here ...
[...]
Persistent Properties

Good point! :)
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Some YouTube videos
Johan G
Moderator
 
Posts: 6629
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit

Re: Read/Write from files via Nasal

Postby Octal450 » Tue May 23, 2017 11:47 pm

Does this work even if the user closes FlightGear the "bad" way? (X-button)

I have this at some point used:
Code: Select all
var MD88_Savedata = func {
  aircraft.data.add("/controls/lighting/digital-norm");      # Numeric readouts lighting
  aircraft.data.add("/controls/lighting/pfd-norm");      # Primary flight display lighting
  aircraft.data.add("/controls/lighting/nd-norm");      # Navigational display lighting
  aircraft.data.add("/controls/lighting/panel-norm");      # Standard instrument lighting
  aircraft.data.add("/options/retrofit");   # Retrofit
}


But, if I exit FlightGear the "bad" way, it does no save a thing.

This is why I want to write it immediately when the setting is toggled.

@jam007
I seen that, but I did not think about READ ALLOW and WRITE ALLOW -- sorry! (I must have been tired)

So to make sure I am not stupider than I already am, I could write to: $FG_HOME/Export/A320settings.conf

But if the file doesn't exist, then I must create it there, since it is outside of the Aircraft's folder.

Wiki says: r+ Open for input and output operations. The file must exist.

But if the file no exists, then I get nasal parse error.
http://prntscr.com/fbcb76

So the Wiki says: a+ Opens a file for input and output operations. Output operations will append data to the end of the file. Input operations are affected by seek() , but output operations will move the position back to the end of the file. The file is created if it does not exist.

But he lies! I still get the same parse error! I made a typo. It works now. Let me try to see if I can read from it properly.

Code: Select all
var file = io.open(getprop("/sim/fg-home")~"/Export/A320settings.conf","a+");




Kind Regards,
Josh
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: Read/Write from files via Nasal

Postby Necolatis » Tue May 23, 2017 11:54 pm

Just run this nasal command once:

aircraft.data.save(0.5);# save the data list every 30 seconds
"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

Re: Read/Write from files via Nasal

Postby Necolatis » Tue May 23, 2017 11:57 pm

Or this when you want them to be saved:

aircraft.data.save();
"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

Re: Read/Write from files via Nasal

Postby Octal450 » Wed May 24, 2017 12:09 am

I'll keep that in mind.

I will use that, as this is not reliable enough.
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: Read/Write from files via Nasal

Postby Octal450 » Wed May 24, 2017 12:36 am

@Necolatis
Working, thank you.
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

Previous

Return to Development

Who is online

Users browsing this forum: No registered users and 10 guests