[Solved]love.filesystem problems...

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.
Post Reply
User avatar
FierceForm
Prole
Posts: 10
Joined: Sat Jan 22, 2011 4:35 pm

[Solved]love.filesystem problems...

Post 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?
Last edited by FierceForm on Sat Jan 22, 2011 7:58 pm, edited 1 time in total.
-FierceForm
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: love.filesystem problems...

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

Re: love.filesystem problems...

Post 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.
Help us help you: attach a .love.
User avatar
FierceForm
Prole
Posts: 10
Joined: Sat Jan 22, 2011 4:35 pm

Re: love.filesystem problems...

Post by FierceForm »

Thanks for the responses.
-FierceForm
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

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

Post by TechnoCat »

Anyone that ran the code in the first post.
Remove the conf.lua from ~/.local/share/love (%appdata%\love) it creates.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 5 guests