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 3:28 pm

jam007
 
Posts: 477
Joined: Sun Dec 16, 2012 10:04 am
Location: Uppsala, Sweden
Version: 2017.3.1
OS: Ubuntu 16.04

Re: Read/Write from files via Nasal

Postby Thorsten » Sun May 21, 2017 4: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: 9367
Joined: Mon Nov 02, 2009 8:33 am

Re: Read/Write from files via Nasal

Postby it0uchpods » Tue May 23, 2017 1: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
it0uchpods/WTF411

Do not expect immediate responses. I do not log in often. I do not answer PMs from non-admins.
I only monitor IDG Development and Support Threads. Everything else is ignored.
Download High Quality Aircraft from it0uchpods Hanger
User avatar
it0uchpods
 
Posts: 3278
Joined: Tue Oct 06, 2015 12:51 pm
Version: 2018.1.1
OS: Windows 8.1 x64

Re: Read/Write from files via Nasal

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

it0uchpods wrote in Tue May 23, 2017 1: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 11:57 am
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 7:52 pm

sanhozay wrote in Tue May 23, 2017 1: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)
Johan G
Moderator
 
Posts: 5266
Joined: Fri Aug 06, 2010 5:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 3.0.0
OS: Windows 7, 32 bit

Re: Read/Write from files via Nasal

Postby it0uchpods » Tue May 23, 2017 10: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
it0uchpods/WTF411

Do not expect immediate responses. I do not log in often. I do not answer PMs from non-admins.
I only monitor IDG Development and Support Threads. Everything else is ignored.
Download High Quality Aircraft from it0uchpods Hanger
User avatar
it0uchpods
 
Posts: 3278
Joined: Tue Oct 06, 2015 12:51 pm
Version: 2018.1.1
OS: Windows 8.1 x64

Re: Read/Write from files via Nasal

Postby Necolatis » Tue May 23, 2017 10: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


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

Re: Read/Write from files via Nasal

Postby Necolatis » Tue May 23, 2017 10: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


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

Re: Read/Write from files via Nasal

Postby it0uchpods » Tue May 23, 2017 11:09 pm

I'll keep that in mind.

I will use that, as this is not reliable enough.
it0uchpods/WTF411

Do not expect immediate responses. I do not log in often. I do not answer PMs from non-admins.
I only monitor IDG Development and Support Threads. Everything else is ignored.
Download High Quality Aircraft from it0uchpods Hanger
User avatar
it0uchpods
 
Posts: 3278
Joined: Tue Oct 06, 2015 12:51 pm
Version: 2018.1.1
OS: Windows 8.1 x64

Re: Read/Write from files via Nasal

Postby it0uchpods » Tue May 23, 2017 11:36 pm

@Necolatis
Working, thank you.
it0uchpods/WTF411

Do not expect immediate responses. I do not log in often. I do not answer PMs from non-admins.
I only monitor IDG Development and Support Threads. Everything else is ignored.
Download High Quality Aircraft from it0uchpods Hanger
User avatar
it0uchpods
 
Posts: 3278
Joined: Tue Oct 06, 2015 12:51 pm
Version: 2018.1.1
OS: Windows 8.1 x64

Previous

Return to Development

Who is online

Users browsing this forum: No registered users and 1 guest