Code: Select all
local f = love.filesystem.newFile("bla")
f:open("w")
AFAIK, newFile doesn't even try to open a file, but f:open() does.
Code: Select all
local f = love.filesystem.newFile("bla")
f:open("w")
Yes that's what I mean, if you open a non existant file with write it would be created, however to open a file you would have to first set a fileobject and according to the docs (wich are probably wrong) you can use love.filesystem.newFile("filename") only to assign file objects to existing files. Meaning you can't assign a fileobject preventing you from using fileobject:open("w").Robin wrote:If you open a file for writing (), the file is created.Code: Select all
local f = love.filesystem.newFile("bla") f:open("w")
AFAIK, newFile doesn't even try to open a file, but f:open() does.
http://love2d.org/docs/love_filesystem_newFile_1.html wrote:love.filesystem.newFile( filename )
Creates a new File object. An error will occur if the specified file does not exist.
That would be awesome., I'll do some own research in the meantime.bartbes wrote: EDIT: I might be able to give you a working example this afternoon.
I fixed the docs.mrklotz wrote:Yes that's what I mean, if you open a non existant file with write it would be created, however to open a file you would have to first set a fileobject and according to the docs (wich are probably wrong) you can use love.filesystem.newFile("filename") only to assign file objects to existing files. Meaning you can't assign a fileobject preventing you from using fileobject:open("w").
Code: Select all
--conf.lua
function love.conf(t)
t.screen = false
--whatever else you want
end
--main.lua
function love.load()
local w, h
if love.filesystem.exists("configuration.txt")
local f = love.filesystem.newFile("configuration.txt")
f:open("r")
local it = f:lines()
w = tonumber(it()) --read first line as width
h = tonumber(it()) --and second as height
f:close()
--you might want to do some more checks for valid data here
else
w = 800
h = 600
end
setres(800, 600)
end
function savetheshit(w, h) --the function that saves it, w being width, h being height
local f = love.filesystem.newFile("configuration.txt")
f:open("w")
f:write(("%d\n%d"):format(w, h))
f:close()
end
function setres(w, h)
love.graphics.setMode(w, h, false, true, 0)
end
You forgot the "then" after the first if- fork but other than that it runs perfectly fine.bartbes wrote:Haven't tested it, but this should work.
Code: Select all
[sectionheader]
setting1= 800
setting2 = 600
setting3= true
[sectionheader2]
anothersetting= 12
Code: Select all
tonumber(breakup("setting1= 800"))
Code: Select all
love.filesystem.load("configfile")()
Code: Select all
local key, value = str:match("(%w+)=(%d+)")
if key and value then
conf[key] = value
end
Users browsing this forum: Ahrefs [Bot] and 2 guests