Page 1 of 1

Can't Make A Save File

Posted: Fri Jun 30, 2017 10:31 pm
by JaredFuntime
Hey there, I need some help on making a save file on a Love2D game.

Here is my code below:

Code: Select all

local data
local quit = true

function love.load()
  cmd = require('require.lovecmd')

  if not love.filesystem.exists('sav.klopman') then
    data = {}
    print('Oh!  Hello there.  I must have been expecting you.')
  else
    data = love.filesystem.load('sav.klopman')
    print('Ah, welcome back, dear player.  Ready to continue playing?')
  end
end

function love.quit()
  if quit then
    print('Are you sure you want to save before quitting?')
    quit = false
  else
    io.write('sav.klopman')
    return quit
  end
  return true
end
Now don't ask me why I chose '.klopman' as the extension, but can you help me fix it?

Re: Can't Make A Save File

Posted: Sat Jul 01, 2017 12:30 am
by zorg
io.write writes to the standard output by default, or in other words, the same place the print function writes to.
Since you do want to use love.filesystem functions instead of lua's io ones, for file manipulation, you should use love.filesystem.write instead.

Also, it wouldn't hurt actually writing something into the file... but of course, you can have a bunch of empty files too, i'm not here to judge. :P

Re: Can't Make A Save File

Posted: Sat Jul 01, 2017 1:06 am
by JaredFuntime
Nevermind, I already got it, because I was waiting for moderator's approval.