LUA file system.

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
slime
Solid Snayke
Posts: 3170
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: LUA file system.

Post by slime »

Roland_Yonaba wrote:Windows 7, x32 for me. Using a standard version of love, this specific one. Am I missing something ?
Here's the example (see *.love attached). With Love 0.7.2 I won't have any problem. But with Love 0.8.0, I just get this screen.
Your love file works fine for me on OSX. Your code tries to create the file in LÖVE's current working directory, which is in the folder the .exe resides in if you run it in Windows, I believe - C:\Program Files\LOVE\ with the default installation. Do you lack admin permissions on that computer? (or perhaps UAC is interfering there? I'm not very familiar with it.)

Note that the default current working directory when you open LÖVE can vary wildly depending on OS, how the user is running LÖVE, and other user-determined factors. It is generally a bad idea to write to it, both because files could end up all over the place and because the executable might not have write permissions in the working directory (as seems to be the case on your system.)
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: LUA file system.

Post by Boolsheet »

slime said the important things. I want to add that io.open returns an error string that should give you an idea of what went wrong:

Code: Select all

local file, errMsg = io.open("somefile.txt", "wb")
if not file then
    error(errMsg or "Error: Don't know why. :(")
end
Edit: The error messages come from the C runtime library and will be worded different on every OS. Just as a warning. ;)
Shallow indentations.
Palmar
Prole
Posts: 23
Joined: Thu Dec 13, 2012 3:54 pm

Re: LUA file system.

Post by Palmar »

Who can help me with saving/loading array? Saving is already done, but i don't understand how to read correctly.
(Saving on "S")
Attachments
main.love
Saving
(599 Bytes) Downloaded 140 times
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: LUA file system.

Post by Kadoba »

This should give you the basic idea.
ReadWrite.love
(735 Bytes) Downloaded 308 times
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: LUA file system.

Post by Roland_Yonaba »

I checked, and double checked, again and again. And it turns out that I was completely wrong.
Apologies for fooling you around, Palmar. And Thanks to slime and Boolsheet and Kadoba for the advice.

Fact is, in my setup, I have two logical drives. And most of my devs tools are located in the second one, the D: drive. As I am using Love (0.8.0) frquently, I have it at the root of this drive. And for some reason (I still dunno why), Lua IO is not granted the right to write anything at the root of the D: drive. I I just move anything in another folder, it works fine.
slime wrote:
Roland_Yonaba wrote:But, actually, as I said in a previous post, it won't work with Löve 0.8.0, as file writing with Lua IO seems to be deprecated.
LÖVE does not modify, remove, or deprecate any standard Lua library or function.
So indeed, Löve doesn't deprecate anything. Slime was totally right. And I was utterly wrong.

@Palmar: The "how-to-load-data-from-file" problem have been discussed a lot of times around. You can try searching.
Anyway, Kadoba's proposal is a clean way to go, it just changes a bit the way you write data in the file, using delimiters to separate each single values. Then he uses string pattern matching to parse back the saved file.
There is an alternate method, where you saves the file as legit Lua code, so that you can load it back very easily, using loadfile or love.filesystem.load.
Palmar
Prole
Posts: 23
Joined: Thu Dec 13, 2012 3:54 pm

Re: LUA file system.

Post by Palmar »

Problem solved. Thanks for assistanse, guys. This theme was very helpful for me.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests