Page 1 of 1
Screenshots not being saved
Posted: Sat Nov 11, 2017 2:29 pm
by AlanGmnz
I'm trying to use the
love.graphics.newScreenshot() function but it's not working. The save folder is also not being created* even though I've already set it with
t.identity. Running love.exe as admin (I'm using Windows 7 by the way) doesn't make any difference.
*Assuming it's C:\Users\user\AppData\Roaming\LOVE as it says on the wiki.
Here's the code I'm using:
conf.lua
main.lua
Code: Select all
-- love.load
-- love.update
function love.keypressed(key, isrepeat)
if key == "s" then
local screenshot = love.graphics.newScreenshot();
screenshot:encode('png', os.time() .. '.png');
end
end
-- love.draw
Re: Screenshots not being saved
Posted: Sat Nov 11, 2017 2:59 pm
by grump
You're not writing the image anywhere.
Code: Select all
love.filesystem.write(os.time() .. '.png', love.graphics.newScreenshot():encode('png'))
Re: Screenshots not being saved
Posted: Sat Nov 11, 2017 3:23 pm
by AlanGmnz
Thanks for replying but I've tried your solution with and without love.filesystem.setIdentity("Demo") in love.load() and it doesn't work. Still no save folder being created either.
Code: Select all
function love.keypressed(key, isrepeat)
if key == "s" then
love.filesystem.write(os.time() .. '.png', love.graphics.newScreenshot():encode('png'))
end
end
Re: Screenshots not being saved
Posted: Sat Nov 11, 2017 4:16 pm
by zorg
If you have t.identity set in your conf lua, then that's already fine as it is.
Save folder on win7 is either C:\Users\user\AppData\Roaming\LOVE\<identity> or C:\Users\user\AppData\Roaming\<identity> if you fused the project beforehand.
It should work, though, either of these:
Code: Select all
love.filesystem.write(tostring(os.time()) .. '.png', love.graphics.newScreenshot():encode('png'))
love.graphics.newScreenshot():encode('png',tostring(os.time()) .. '.png')
Re: Screenshots not being saved
Posted: Sat Nov 11, 2017 4:17 pm
by slime
You can wrap an assert() around the love.filesystem.write call to easily show any error messages it returns, maybe that'll help diagnose the issue.
Re: Screenshots not being saved
Posted: Sat Nov 11, 2017 4:51 pm
by AlanGmnz
Thanks for the help everyone. It turns out I was using two love.keypressed() functions and it didn't occurred that one was overriding the other. I've rewrote them into one if/elseif function and it's working now.
One last question: what string should I use so the screenshots are saved in numbers like: 001, 002, 003...
Re: Screenshots not being saved
Posted: Sat Nov 11, 2017 5:19 pm
by zorg
AlanGmnz wrote: ↑Sat Nov 11, 2017 4:51 pm
Thanks for the help everyone. It turns out I was using two love.keypressed() functions and it didn't occurred that one was overriding the other. I've rewrote them into one if/elseif function and it's working now.
One last question: what string should I use so the screenshots are saved in numbers like: 001, 002, 003...
You mean like the extensions? or the names?
for both, a simple solution would be just keeping a variable around, and using the following:
which is of course string.format, but called on the format string itself.
Re: Screenshots not being saved
Posted: Sat Nov 11, 2017 5:40 pm
by AlanGmnz
zorg wrote: ↑Sat Nov 11, 2017 5:19 pm
AlanGmnz wrote: ↑Sat Nov 11, 2017 4:51 pm
Thanks for the help everyone. It turns out I was using two love.keypressed() functions and it didn't occurred that one was overriding the other. I've rewrote them into one if/elseif function and it's working now.
One last question: what string should I use so the screenshots are saved in numbers like: 001, 002, 003...
You mean like the extensions? or the names?
for both, a simple solution would be just keeping a variable around, and using the following:
which is of course string.format, but called on the format string itself.
I mean the names. I think I understood what you suggested but I'm missing something because the code below just keeps producing a 001.png:
Code: Select all
local counter = 0
love.filesystem.write(tostring("%03d"):format(counter+1) .. '.png', love.graphics.newScreenshot():encode('png'))
Re: Screenshots not being saved
Posted: Sat Nov 11, 2017 5:51 pm
by zorg
you also need to increment the counter and save that new value back:
Code: Select all
local counter = 0
-- ...
counter = counter + 1
love.filesystem.write(tostring("%03d"):format(counter) .. '.png', love.graphics.newScreenshot():encode('png'))
Re: Screenshots not being saved
Posted: Sat Nov 11, 2017 6:16 pm
by AlanGmnz
Oh I see it now. Thanks a lot!