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?
Writing into TXT
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
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;
I get a seeds.txt file in my save-directory with 718273 written inside.
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
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.
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.
Re: Writing into 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?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.
- slime
- Solid Snayke
- Posts: 3166
- 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.)
Re: Writing into TXT
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.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.)
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: 3166
- 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.
Re: Writing into TXT
thanks, I haven't tought of that.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.
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: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Writing into TXT
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.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.)
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 4 guests