Is there a way of saving and loading files from anywhere? Like "C:\users\darlex\Desktop\project1" or "\home\darlex\desktop\project1"?
Im trying to do a game editor thing but i dont know how to do that :/
Is there a way of saving and loading files from anywhere?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Is there a way of saving and loading files from anywhere?
Hi! I wish you have an amazing day!
Re: Is there a way of saving and loading files from anywhere?
I'd suggest the IO library: https://www.lua.org/pil/21.2.2.html
Last edited by Rehtinor on Sat May 04, 2019 11:22 pm, edited 1 time in total.
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Is there a way of saving and loading files from anywhere?
Not easily; löve by default doesn't support that (with the exception of dragging folders and files), but there are a few solutions;
You can either use an external lib like luafilesystem and sacrifice it working with any constructors löve gives you (since they still depend on PhysFS that love.filesystem uses), or you can use my library that for now, allows loading from anywhere: love-fml on github. (and yes, my lib can take care of OS-specific differences in a neat way, so you don't have to worry about that)
You can either use an external lib like luafilesystem and sacrifice it working with any constructors löve gives you (since they still depend on PhysFS that love.filesystem uses), or you can use my library that for now, allows loading from anywhere: love-fml on github. (and yes, my lib can take care of OS-specific differences in a neat way, so you don't have to worry about that)
Last edited by zorg on Sun May 05, 2019 11:43 am, edited 1 time in total.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: Is there a way of saving and loading files from anywhere?
As posted before, you could always do the following.
Code: Select all
-- ***** Load/Save from Anywhere on Computer *****
-- To use, wrap 'filename' with 'mount'.
-- for filename = 'D:/Scripts/Love/test.png'
-- Load Example: love.graphics.newImage( mount( filename ) )
-- Save Example: id:encode('png', mount( filename ) )
-- for dir = 'D:/Scripts/Love'
-- Files in Directory: files = love.filesystem.getDirectoryItems( mount( dir ) )
-- Create Directory: love.filesystem.createDirectory( mount( savedir ) )
mount = function( name )
local ffi = require( 'ffi' )
local lv = ffi.load( 'love' )
ffi.cdef[[ int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath); ]];
ffi.cdef[[ int PHYSFS_setWriteDir(const char *newDir); ]]
local file = name:match( "^.+/(.+)$" ) -- filename
local path = string.sub( name, 1, -(#file+1) ) -- path without filename
lv.PHYSFS_setWriteDir( path )
lv.PHYSFS_mount( path, nil, 0 )
return file
end
Re: Is there a way of saving and loading files from anywhere?
"C:\" is a Windows thing and it won't work across platforms.
You want your game to work on any device, right?
Just save the maps to the appData folder and you should be fine.
Re: Is there a way of saving and loading files from anywhere?
Im trying to do a game/map editor and the fact of saving everything in the appdata thing is tedious.
I want to give that sensation of comfort of saving and loading files from anywhere to anywhere.
Like tilesheets, lua files and etcetera
Hi! I wish you have an amazing day!
Re: Is there a way of saving and loading files from anywhere?
Wow, that's useful! Thanks!Ref wrote: ↑Sun May 05, 2019 12:34 am As posted before, you could always do the following.Code: Select all
-- ***** Load/Save from Anywhere on Computer ***** -- To use, wrap 'filename' with 'mount'. -- for filename = 'D:/Scripts/Love/test.png' -- Load Example: love.graphics.newImage( mount( filename ) ) -- Save Example: id:encode('png', mount( filename ) ) -- for dir = 'D:/Scripts/Love' -- Files in Directory: files = love.filesystem.getDirectoryItems( mount( dir ) ) -- Create Directory: love.filesystem.createDirectory( mount( savedir ) ) mount = function( name ) local ffi = require( 'ffi' ) local lv = ffi.load( 'love' ) ffi.cdef[[ int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath); ]]; ffi.cdef[[ int PHYSFS_setWriteDir(const char *newDir); ]] local file = name:match( "^.+/(.+)$" ) -- filename local path = string.sub( name, 1, -(#file+1) ) -- path without filename lv.PHYSFS_setWriteDir( path ) lv.PHYSFS_mount( path, nil, 0 ) return file end
But... Does work with unix-like systems? ("/home/darlex/desktop/project1/")
Hi! I wish you have an amazing day!
Re: Is there a way of saving and loading files from anywhere?
Thanks! but is a little complex to me. (yes. im retarded)zorg wrote: ↑Sat May 04, 2019 11:14 pm Not easily; löve by default doesn't support that (with the exception of dragging folders and files), but there are a few solutions;
You can either use an external lib like luafilesystem and sacrifice it working with any constructors löve gives you (since they still depend on PhysFS that love.filesystem uses), or you can use my library that for now, allows loading from anywhere: love-fml on github. (and yes, my lib can take care of OS-specific differences in a neat way, so you don't have to worry about that)
Hi! I wish you have an amazing day!
Re: Is there a way of saving and loading files from anywhere?
Frankly speaking, I don't see anything "comfortable" in dealing with file dialogs, etc.
In fact, most modern programs never ask you to browse around the device's filesystem.
A good example would be apps on Android and iOS.
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Is there a way of saving and loading files from anywhere?
Beauty in the eye of the beholder, i guess; frankly, i'd rather know how to navigate the cesspool of a filesystem that modern OS-es have than just blindly rely on apps telling me where they put my files.
As the "Usage" part says on github, you really only need to do require('fml')() if you put the files next to your main.lua; after that, you can use syntax like "drv/c/Program Files/..." for windows or "drv/usr/..." for Linux and similar for OSX to refer to any file on your filesystem... and you can still use "src/..." or "usr/..." for the source or save directories, respectively.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Who is online
Users browsing this forum: Ahrefs [Bot], ChocolateLoxtl and 5 guests