Screenshots not being saved

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.
Post Reply
AlanGmnz
Prole
Posts: 8
Joined: Wed Nov 08, 2017 9:25 pm
Location: Brazil

Screenshots not being saved

Post 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

Code: Select all

t.identity = "Demo"
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
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Screenshots not being saved

Post by grump »

You're not writing the image anywhere.

Code: Select all

love.filesystem.write(os.time() .. '.png', love.graphics.newScreenshot():encode('png'))
AlanGmnz
Prole
Posts: 8
Joined: Wed Nov 08, 2017 9:25 pm
Location: Brazil

Re: Screenshots not being saved

Post 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
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Screenshots not being saved

Post 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')
Me and my stuff :3True 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.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Screenshots not being saved

Post 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.
AlanGmnz
Prole
Posts: 8
Joined: Wed Nov 08, 2017 9:25 pm
Location: Brazil

Re: Screenshots not being saved

Post 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...
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Screenshots not being saved

Post 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:

Code: Select all

("%03d"):format(counter)
which is of course string.format, but called on the format string itself.
Me and my stuff :3True 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.
AlanGmnz
Prole
Posts: 8
Joined: Wed Nov 08, 2017 9:25 pm
Location: Brazil

Re: Screenshots not being saved

Post 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:

Code: Select all

("%03d"):format(counter)
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'))
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Screenshots not being saved

Post 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'))
Me and my stuff :3True 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.
AlanGmnz
Prole
Posts: 8
Joined: Wed Nov 08, 2017 9:25 pm
Location: Brazil

Re: Screenshots not being saved

Post by AlanGmnz »

Oh I see it now. Thanks a lot!
Post Reply

Who is online

Users browsing this forum: No registered users and 142 guests