saving files to game directory

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.
russ_e
Prole
Posts: 11
Joined: Wed Sep 05, 2012 12:15 pm

saving files to game directory

Post by russ_e »

Hey all,
I'm trying to figure out how to get my little game running as a .love file, and its complaining that it cant find files, which makes sense, since they're not saved in the main game directory. I've looked, and cant find any info anywhere about how to change the directory you're saving in from the ...AppData\Roaming\LOVE\gamename directory to the ...love\game directory.

my first ATTEMPT to get it working with a local directory was something like this (didnt work :( )

Code: Select all

function map_startup()
	current_map = "map1.lua"
	map_path = "states/game/maps/"
	load_map()
end

function load_map()
	
	local file = love.filesystem.newFile(map_path..current_map)
	local temp_string_map = {}
	local new_map = {}
	
	map = {}  --GLOBAL

	for line in love.filesystem.lines(map_path..current_map) do
		table.insert(temp_string_map, line)
	end
	
	map_h = #temp_string_map
	map_w = string.len(temp_string_map[1])
	
	for y = 1, map_h do
		new_map = {}
		tempstring = string.sub(temp_string_map[y], 1, map_w)
		for x = 1, map_w do
			new_map[x] = tonumber(string.sub(tempstring, x, x))
		end
		
		table.insert(map, new_map)
	end	
end
Help greatly appreciated :)

Once i get this working, i'll probably be back within seconds to ask if anyone can help figure out why my collision detection is so flakey :P
Attachments
game.zip
(223.9 KiB) Downloaded 196 times
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: saving files to game directory

Post by coffee »

russ_e wrote:and cant find any info anywhere about how to change the directory you're saving in from the ...AppData\Roaming\LOVE\gamename directory to the ...love\game directory.
You are probably looking for this.
https://love2d.org/wiki/love.filesystem.setIdentity
However you are always limited in save area choices. But you can load from whatever place you want inside your LOVE file.
Check the limitations here
https://love2d.org/wiki/love.filesystem
russ_e
Prole
Posts: 11
Joined: Wed Sep 05, 2012 12:15 pm

Re: saving files to game directory

Post by russ_e »

many thanks :D

<3
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: saving files to game directory

Post by Roland_Yonaba »

Just to mention that, working with Love 0.8.0, you can also set that in your conf.lua.

Code: Select all

function love.conf(config)
	config.identity = "whatever"
end
russ_e
Prole
Posts: 11
Joined: Wed Sep 05, 2012 12:15 pm

Re: saving files to game directory

Post by russ_e »

Ok, that seems to work for loading files - can i change the directory it saves out to? They always seem to get thrown in roaming, despite my better efforts...
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: saving files to game directory

Post by Nixola »

It's the only directory where programs can write without asking for administrator rights, so it will only write in there.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
russ_e
Prole
Posts: 11
Joined: Wed Sep 05, 2012 12:15 pm

Re: saving files to game directory

Post by russ_e »

Ah, that's rather rubbish, I'll have to fiddle with stuff to get my level editor working.

Thanks very much for the answer though :)
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: saving files to game directory

Post by Roland_Yonaba »

Each game is granted a single directory on the system where files can be saved through love.filesystem. This is the only directory where love.filesystem can write files. These directories will typically be found in something like:
Seen on love.filesystem.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: saving files to game directory

Post by coffee »

Roland_Yonaba wrote:
Each game is granted a single directory on the system where files can be saved through love.filesystem. This is the only directory where love.filesystem can write files. These directories will typically be found in something like:
Seen on love.filesystem.
russ_e is for some reason ignoring what we (and LOVE wiki) say to him. He already was warned before about the limitations.
You are probably looking for this.
https://love2d.org/wiki/love.filesystem.setIdentity
However you are always limited in save area choices. But you can load from whatever place you want inside your LOVE file.
Check the limitations here
https://love2d.org/wiki/love.filesystem
russ_e is a very distracted person. :D
russ_e
Prole
Posts: 11
Joined: Wed Sep 05, 2012 12:15 pm

Re: saving files to game directory

Post by russ_e »

Sorry if i upset you, coffee, i'm just new and asking for help. I guess i'll go elsewhere in the future.
Post Reply

Who is online

Users browsing this forum: No registered users and 87 guests