saving png as different file name if it exists

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
raptrex
Posts: 9
Joined: Thu Sep 29, 2005 11:58 am
Contact:

saving png as different file name if it exists

Post by raptrex »

for the base of my "paint" application, im using this script from the tutorial:

Code: Select all

red = Color.new(255, 0, 0);
black = Color.new(0, 0, 0);
white = Color.new(255, 255, 255);

canvas = Image.createEmpty(480, 272)
canvas:clear(white)

brush = {}
eraser = {}

x0 = 0
y0 = 0
x1 = 0
y1 = 0
while true do
	pad = Controls.read()
	dx = pad:analogX()
	if math.abs(dx) > 32 then
		x0 = x0 + dx / 64
	end
	dy = pad:analogY()
	if math.abs(dy) > 32 then
		y0 = y0 + dy / 64
	end
	if pad:cross() then
		canvas:drawLine(x0, y0, x1, y1, black)
	end
	x1 = x0
	y1 = y0
	screen:blit(0, 0, canvas, 0, 0, canvas:width(), canvas:height(), false)
	screen:drawLine(x1 - 5, y1, x1 + 5, y1, red)
	screen:drawLine(x1, y1 - 5, x1, y1 + 5, red)
	screen.waitVblankStart()
	screen.flip()
	if pad:start() then break end
	if pad:select() then screen:save("screenshot.png") end
end
with the use of png instead of tga

how would i do this?:

if screenshot.png exists, save image as screenshot1.png
if screenshot1.png exists, save image as screenshot2.png
ect ect ect

maybe to infinity and beyond
or 10 for now
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

Code: Select all

function ScreenShot()
    name='screenshot_'
    counter=0
    extension='.png'
    while io.open(name..counter..extension, "r") do
        counter=counter+1
        io.close()
    end
    --reached a filename that does not exist.
    screen:save(name..counter..extension)
end
this code is untested, but i guess it should work.
plz post if it really works and if not, what happens (or report the fix)

greets
lumo
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
raptrex
Posts: 9
Joined: Thu Sep 29, 2005 11:58 am
Contact:

Post by raptrex »

it works perfectly THANK YOU!!!!
your my hero
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

fine!
uploaded the lua-file to my webpage :)

greets
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
paulieweb
Posts: 8
Joined: Thu Nov 03, 2005 10:18 am
Location: PSU
Contact:

Post by paulieweb »

i tried both raptrex's original screenshot code from the tutorial and lumo's screenshot function, and neither saves a screenshot anywhere on my stick. when i hit the button, the memory stick light flashes like it's saving, but i can't find it. anybody else with this problem?
chaos
Posts: 135
Joined: Sun Apr 10, 2005 5:05 pm

Post by chaos »

paulieweb wrote:i tried both raptrex's original screenshot code from the tutorial and lumo's screenshot function, and neither saves a screenshot anywhere on my stick. when i hit the button, the memory stick light flashes like it's saving, but i can't find it. anybody else with this problem?
yeah.. don't use usb mode when taking screenshots, they won't show up.. and you can end up corrupting the memory stick, requiring a reformat.
Chaosmachine Studios: High Quality Homebrew.
paulieweb
Posts: 8
Joined: Thu Nov 03, 2005 10:18 am
Location: PSU
Contact:

Post by paulieweb »

whew, thanks a lot
Master Inuyasha
Posts: 13
Joined: Sun Nov 13, 2005 9:55 am

Post by Master Inuyasha »

hey, something is wrong, i installed that into my script, and made it so that when you press pad, it takes a screenshot, but it doesnt work. Heres my code:

elseif pad:select() then
function ScreenShot()
name='ms0:/PSP/PHOTO/screenshot_'
counter=0
extension='.png'
while io.open(name..counter..extension, "r") do
counter=counter+1
io.close()
end
--reached a filename that does not exist.
screen:save(name..counter..extension)
end
end

says got nil calling global value
Post Reply