love.filesystem trouble, doesn't seem to work.

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

Re: love.filesystem trouble, doesn't seem to work.

Post by Robin »

bartbes wrote:If you enable the console, do you see any output?
If you don't know how to enable the console, see: http://love2d.org/docs/love_conf.html
(In short: have a file called conf.lua containing

Code: Select all

function love.conf(t)
    t.console = true
end
)
Help us help you: attach a .love.
User avatar
Clavus
Prole
Posts: 28
Joined: Wed Jan 27, 2010 12:45 pm

Re: love.filesystem trouble, doesn't seem to work.

Post by Clavus »

bartbes wrote:If you enable the console, do you see any output?
Nope. The function just ends while evaluating the love.filesystem.write(CONFIG_FILE, DefaultConfigString()) part. It prints "a", but neither "b" nor "c".
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: love.filesystem trouble, doesn't seem to work.

Post by bartbes »

And this code?

Code: Select all

local function LoadConfig()
   
   local CONFIG_FILE = "config.txt" -->we don't use absolute paths, it's a myth, a bad one.
   
   print("Attempting to load config")
   print("File path: "..CONFIG_FILE)
   local cfgfile = nil
   if (love.filesystem.exists(CONFIG_FILE)) then
      cfgfile = love.filesystem.newFile(CONFIG_FILE)
   else
      print("a")
      if (love.filesystem.write(CONFIG_FILE, DefaultConfigString())) then
         print("b")
         cfgfile = love.filesystem.newFile(CONFIG_FILE)
      else
         print("c")
         error("Can't read and/or create config.txt file.")
      end
   end
   
   cfgfile:open("r")  --> DON'T FORGET THIS
   for k, v in pairs(cfgfile:lines()) do
      print("Line "..k.." = "..v)
   end

end

local function DefaultConfigString()

   return [[m1 +primary
         m2 +secondary
         w +forward
         a +left
         d +right
         s +back]]
end
User avatar
mrklotz
Prole
Posts: 17
Joined: Mon Jan 25, 2010 1:53 pm

Re: love.filesystem trouble, doesn't seem to work.

Post by mrklotz »

bartbes wrote:The path is supposed to be extracted from your environment variables, try finding the one that points to C:\\Users and change it to C:\\Gebruikers. (though I must say I am horrified by them even thinking about localizing such paths, microsoft never ceases to amaze me)
The localization is actually just a link to the true "c:\users" folder, if you navigate via cmd-line and use dir you will see your users- Directory, it's the same thing in vista.
Win7 does use a diffrent layout for the folder structue for "my music" etc but even that is linked onto the older structure of vista.

tl;dr version:

It's the same thing using the loclaized folder name or the english "true name" of the folder, because the localized is just a link to the hidden folder named in english.
User avatar
Clavus
Prole
Posts: 28
Joined: Wed Jan 27, 2010 12:45 pm

Re: love.filesystem trouble, doesn't seem to work.

Post by Clavus »

bartbes wrote:And this code?
Nope, it still doesn't get to print("b") or print("c"). I think the fact that there's no save folder being created might play a large role.
User avatar
Clavus
Prole
Posts: 28
Joined: Wed Jan 27, 2010 12:45 pm

Re: love.filesystem trouble, doesn't seem to work.

Post by Clavus »

Does anyone have a working example of saving files to the save folder? Maybe I can compare my code to that just to be sure.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: love.filesystem trouble, doesn't seem to work.

Post by bartbes »

User avatar
Clavus
Prole
Posts: 28
Joined: Wed Jan 27, 2010 12:45 pm

Re: love.filesystem trouble, doesn't seem to work.

Post by Clavus »

bartbes wrote:Of course!
Thanks, that helped a lot. Got it working!

Code: Select all

	print("Attempting to load config")
	print("File path: "..CONFIG_FILE)
	local cfgfile = nil
	if (love.filesystem.exists(CONFIG_FILE)) then
		cfgfile = love.filesystem.newFile(CONFIG_FILE)
	else
		cfgfile = love.filesystem.newFile(CONFIG_FILE)
		cfgfile:open("w")
		if (cfgfile:write(DefaultConfigString())) then
			cfgfile:close()
			cfgfile = love.filesystem.newFile(CONFIG_FILE)
		else
			error("Can't read and/or create config.txt file.")
		end
	end
User avatar
subrime
Citizen
Posts: 76
Joined: Thu Nov 13, 2008 6:18 pm
Location: Australia

lbp and lua 5.2

Post by subrime »

bartbes: looking through your lbp code a bit... did you know lua 5.2 is planning to drop setfenv?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: love.filesystem trouble, doesn't seem to work.

Post by bartbes »

I know, I'm planning to drop lua 5.2 :P (but yeah, I knew)
Post Reply

Who is online

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