Page 1 of 2

Writing into TXT

Posted: Sat Jun 27, 2015 11:30 am
by ~Tidal
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?

Re: Writing into TXT

Posted: Sat Jun 27, 2015 1:00 pm
by BOT-Brad
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.

Re: Writing into TXT

Posted: Sat Jun 27, 2015 1:24 pm
by ~Tidal
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.

Re: Writing into TXT

Posted: Sat Jun 27, 2015 1:39 pm
by Robin
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.

Re: Writing into TXT

Posted: Sat Jun 27, 2015 3:33 pm
by ~Tidal
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?

Re: Writing into TXT

Posted: Sat Jun 27, 2015 3:53 pm
by slime
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.)

Re: Writing into TXT

Posted: Sat Jun 27, 2015 4:00 pm
by ~Tidal
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.

Re: Writing into TXT

Posted: Sat Jun 27, 2015 4:12 pm
by slime
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.

Re: Writing into TXT

Posted: Sat Jun 27, 2015 4:25 pm
by ~Tidal
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 :). :awesome:

Re: Writing into TXT

Posted: Sat Jun 27, 2015 6:01 pm
by zorg
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.