Page 1 of 1

Can no longer take screenshots with last love2d version

Posted: Mon Feb 03, 2020 10:59 am
by mojojojo
Hello I'm stuck on a problem that should be easy to overcome. I used to run a script that take screenshots of the window on my old computer which was unable to run love2d past the 10.0 version. Now I have a new computer and the last love2d ans apparently I have to use love.graphics.captureScreenshot instead of love.graphics.newScreenshot.

But when I do that there's no image in the target folder folder. In my old code I have another line screenshot:encode('png', os.time() .. '.png') but if I use it now it crashes saying the golbal "screenshot" in a nil value BUT there's is an image created, an actual screenshot of the crash message.

I'm oblivious to the problem and I'd appreciate your help. The attached code is short and very easy to understand.

Re: Can no longer take screenshots with last love2d version

Posted: Mon Feb 03, 2020 11:15 am
by raidho36
The screenshot capture function returns nothing, it just takes a screenshot and saves it to the filesystem. No additional action is needed. Your followup line causes a crash because you're trying to call a function on nil object (because capture screenshot didn't return anything). The screenshot is that of the error message, because that's what was rendered at the end of that frame.

Re: Can no longer take screenshots with last love2d version

Posted: Mon Feb 03, 2020 12:01 pm
by zorg
While it's true that the captureScreenshot method doesn't return anything directly, you can also give it a Channel or a function as well; the former's only interesting if you work with threads, the latter can be more useful since captureScreenshot will call that supplied function with an ImageData of the screenshot when it finished capturing it... but for your use-case, the filename variant is fine.

Re: Can no longer take screenshots with last love2d version

Posted: Mon Feb 03, 2020 6:10 pm
by mojojojo
I didn't understand how channels works but love.image.newImageData worked so I can just draw the screen to a virtual one (ImageData) then make a screenshot out of it. The good news on top of that is that I can manipulate pixels if I ever want to add effects.

I'll keep the channel thing in mind when I'm good enough in programming to use it. Thank you people.