Page 1 of 1

[Solved]love.filesystem problems...

Posted: Sat Jan 22, 2011 5:53 pm
by FierceForm
Hello,

I'm new to the forums, although I've used Love a bit before (It's been a while, my Lua skills are pretty rusty). But I'm developing a game where I want to create a folder in the user's documents directory for placing files that the user can load and play in the game. So, I'm checking to see if the directory exists when the game starts up, and if it doesn't, I'm going to create it. When creating the directory, love.filesystem.mkdir returned false. So I decided to also attempt to write to my conf.lua file to see if that worked, and I got an error saying the write directory couldn't be set. Here's my code so far. Here's the code.

Code: Select all

function love.load()
	-- Creates the songs directory if it doesn't exist
	sdir = love.filesystem.getUserDirectory() .. "SortMania 2 Songs"
	print(sdir)
	if (not love.filesystem.exists(sdir)) then
		print("Directory doesn't exist... Attempting to create:")
		print(love.filesystem.mkdir(sdir))
	end
	
	file = love.filesystem.newFile("conf.lua")
	file:open("a")
	file:write("-- Hello.")
	
    -- Create the physics world
    world = love.physics.newWorld(-2000,-2000,2000, 2000)
    world:setGravity(0, 50)
    
end

function love.update(dt)
    -- Update the world.
    world:update(dt)
end
I tried running the program as an administrator with similar results... Any ideas?

Re: love.filesystem problems...

Posted: Sat Jan 22, 2011 6:03 pm
by tentus
You have to operate within the Love application data directory, for security reason: see love.filesystem. Also read over setIdentity to get an idea of what is and isn't doable.

Re: love.filesystem problems...

Posted: Sat Jan 22, 2011 6:24 pm
by Robin
Try

Code: Select all

sdir = "SortMania 2 Songs"
(directories are all relative to either the .love or the write directory)
Losing the spaces in pathnames would be a good idea. Plus, you'll want to set a proper identity (most likely in love.conf), and just use the subdirectory "songs" or something.

Re: love.filesystem problems...

Posted: Sat Jan 22, 2011 7:58 pm
by FierceForm
Thanks for the responses.

Re: [Solved]love.filesystem problems...

Posted: Sat Jan 22, 2011 10:06 pm
by TechnoCat
Anyone that ran the code in the first post.
Remove the conf.lua from ~/.local/share/love (%appdata%\love) it creates.