Old 01-18-2019, 05:48 AM   #1
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 618
Default Read and write from file on disk

Hi

Is it possible (I presume it must be?) to allow a Reaper script to create, write to, read from and delete a small file on the hard disk?

I can think of some uses for this, such as storing the state of an array or variable in a file (somehow! not sure of what form the data would need to take) so that a script can run multiple times, but always make decisions based on the state of events when it was run the first time.

There may be another way to do this, but any pointers/resources would be welcome.

Thanks
Andy
andyp24 is offline   Reply With Quote
Old 01-18-2019, 05:58 AM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,545
Default

Yes, all ReaScripts (Lua, Python and ELL) can read and write files (except if run with restricted permissions).

https://www.lua.org/manual/5.3/manual.html#6.8
https://www.lua.org/manual/5.3/manua...#pdf-os.remove

There's also REAPER's temporary, permanent and project extstates.

Last edited by cfillion; 01-18-2019 at 06:06 AM.
cfillion is offline   Reply With Quote
Old 01-18-2019, 06:29 AM   #3
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 618
Default

Ok, ExtState sounds like it might be the way to go, as this is only for temporary use within an edit, and would never need to be recalled after the project was closed etc.

Is there a resource to learn about this please?

Thanks
andyp24 is offline   Reply With Quote
Old 01-18-2019, 06:39 AM   #4
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,545
Default

Search for "ExtState" in the ReaScript documentation (Help menu in REAPER). The functions are SetExtState, HasExtState, GetExtState and DeleteExtState. An extstate is identified by a section and key of your choice. The section is usually chosen to be unique to the script and the key to identify the data being stored. Set the "persist" argument to false in order to have the extstate stored only until REAPER is closed.
cfillion is offline   Reply With Quote
Old 01-18-2019, 06:46 AM   #5
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 618
Default

Yeah, I see them in the API documentation, but as someone very new to scripting of any kind, I was hoping for an idiot's guide :-)

I guess I'll just experiment and see what I can make it do.

Thanks
Andy
andyp24 is offline   Reply With Quote
Old 01-18-2019, 07:54 AM   #6
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,500
Default

You should consider inspecting already made script, you have tons of exemple of file reading and exporting there :P

Also check sitepoint tutorial about Lua I/O, very well done doc.
X-Raym is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:06 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.