## Writing into TXT

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
~Tidal
Prole
Posts: 27
Joined: Sat Jan 10, 2015 8:19 pm

### Writing into TXT

I set an rng with a random seed, and I wanted it to print the seed in a txt file.
I've tried every i/o formula, love.filesystem.write("seeds.txt", tostring(seed)), sometimes literally copying and pasting them from the net, but still, the file is always blank when I open it.
I even put those formulas in love.update, expecting an huge resources use, maybe a crash. Nothing. Blank file, everything works fine except this.
Where did I go wrong?

BOT-Brad
Citizen
Posts: 87
Joined: Tue Dec 02, 2014 2:17 pm
Location: England

### Re: Writing into TXT

Are you sure the variable seed is set? Have you set your projects save-directory using love.filesystem.setIdentity or by setting t.identity = XXX inside your conf.lua?

Your code works fine for me in an example project such as this;

Code: Select all

function love.load()
local seed = 718273
love.filesystem.write("seeds.txt", tostring(seed))
end

I get a seeds.txt file in my save-directory with 718273 written inside.
Follow me on GitHub! | Send me a friend request on PSN!

~Tidal
Prole
Posts: 27
Joined: Sat Jan 10, 2015 8:19 pm

### Re: Writing into TXT

The "save directory" is nil, it should save in the same directory main.lua is? But seeds.txt keeps being blank
I don't know.

Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

### Re: Writing into TXT

No. LÖVE will never write to the game directory. Check the output of love.filesystem.getSaveDirectory() to find out where to look for seeds.txt.
Help us help you: attach a .love.

~Tidal
Prole
Posts: 27
Joined: Sat Jan 10, 2015 8:19 pm

### Re: Writing into TXT

Robin wrote:No. LÖVE will never write to the game directory. Check the output of love.filesystem.getSaveDirectory() to find out where to look for seeds.txt.
That was the problem. Now, the next problem is: how could i make it save it in the same game directory, or love.exe directory, without writing the whole url?

slime
Solid Snayke
Posts: 2900
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

### Re: Writing into TXT

You can't write to the exe or source game directory with love.filesystem. In fact, in most cases the operating system won't give programs permission to write there at all, no matter what API is used (LÖVE or no LÖVE.)

~Tidal
Prole
Posts: 27
Joined: Sat Jan 10, 2015 8:19 pm

### Re: Writing into TXT

slime wrote:You can't write to the exe or source game directory with love.filesystem. In fact, in most cases the operating system won't give programs permission to write there at all, no matter what API is used (LÖVE or no LÖVE.)
Well...now that I think of it, when packing everything up, those folders won't even be accessible. It actually makes me write only in appdata/roaming. It could be fine finding a more convenient folder (I can only create subfolders), but seems I can't.
Thanks anyway people, you were hella fast + efficient! I spent a night wondering why that .txt was always blank!
Also seems the data usage of filesystemwrite/append is really, really low, since my PC didn't lift off when I put it in love.update.

slime
Solid Snayke
Posts: 2900
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

### Re: Writing into TXT

The appdata folder is pretty hidden on most systems, but at least you can use [wiki]love.system.openURL[/wiki] to programmatically open an Explorer window to a specific folder.

~Tidal
Prole
Posts: 27
Joined: Sat Jan 10, 2015 8:19 pm

### Re: Writing into TXT

slime wrote:The appdata folder is pretty hidden on most systems, but at least you can use [wiki]love.system.openURL[/wiki] to programmatically open an Explorer window to a specific folder.
thanks, I haven't tought of that.
As far as I'm concerned, the file is more important to me than a player, but it's something anyway!
Thanks for the support, I wasn't expecting this .

zorg
Party member
Posts: 2995
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: Writing into TXT

slime wrote:You can't write to the exe or source game directory with love.filesystem. In fact, in most cases the operating system won't give programs permission to write there at all, no matter what API is used (LÖVE or no LÖVE.)
Technically, you can (with love.filesystem even) if you code some questionable things, but as slime said, most OS-es pamper you like a kid, not allowing you to write to most directories effectively forcing you to use their warped idea of content structure... which, sadly, in most cases is very much warranted behaviour on the OS's side.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

### Who is online

Users browsing this forum: No registered users and 28 guests