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.
User avatar
~Tidal
Prole
Posts: 27
Joined: Sat Jan 10, 2015 8:19 pm

Writing into TXT

Post 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?
User avatar
BOT-Brad
Citizen
Posts: 87
Joined: Tue Dec 02, 2014 2:17 pm
Location: England

Re: Writing into TXT

Post 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.
Follow me on GitHub! | Send me a friend request on PSN!
User avatar
~Tidal
Prole
Posts: 27
Joined: Sat Jan 10, 2015 8:19 pm

Re: Writing into TXT

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Writing into TXT

Post 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.
Help us help you: attach a .love.
User avatar
~Tidal
Prole
Posts: 27
Joined: Sat Jan 10, 2015 8:19 pm

Re: Writing into TXT

Post 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?
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Writing into TXT

Post 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.)
User avatar
~Tidal
Prole
Posts: 27
Joined: Sat Jan 10, 2015 8:19 pm

Re: Writing into TXT

Post 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.
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Writing into TXT

Post 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.
User avatar
~Tidal
Prole
Posts: 27
Joined: Sat Jan 10, 2015 8:19 pm

Re: Writing into TXT

Post 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:
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Writing into TXT

Post 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.
Me and my stuff :3True 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 7 guests