CapnMuffin
Member
Code:
module Screen
@screen = Win32API.new 'screenshot', 'Screenshot', %w(l l l l p l l), ''
@readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
@findwindow = Win32API.new 'user32', 'FindWindowA', %w(p p), 'l'
module_function
# Settings for file name and file type.
def shot(file = "pic_camera", typ = 2)
if typ == 0
typname = ".bmp"
elsif typ == 1
typname = ".jpg"
elsif typ == 2
typname = ".png"
end
file_index = 1
# File directory.
dir = "Graphics/Pictures/"
# File tag.
file_name = dir + file.to_s + "_#{file_index}" + typname.to_s
# New tag/file if one exists already.
if FileTest.exist?(file_name)
file_name = dir + file.to_s + "_#{file_index + 1}" + typname.to_s
else
file_name = dir + file.to_s + "_#{file_index}" + typname.to_s
end
@screen.call(0,0,640,480,file_name,handel,typ)
end
def handel
game_name = "0" * 256
@readini.call('Game','Title','',game_name,255,".Game.ini")
game_name.delete!("0")
return @findwindow.call('RGSS Player',game_name)
end
end
So I was playing around with making an efficient screen capture script that can take an infinite amount of them and save them off to the "Pictures" folder. I have one problem with it that I know has a very simple solution, but I can't seem to figure it out.
The problem is the way the code is set up. "index" is constantly reset to "1". Here's what happens...
- The code runs once and "pic_camera1.png" is created. (the 1 being what "index" equals)
- Code runs again, recognizes "pic_camera(index).png" already exists, so creates "pic_camera2.png" (index +1)
- Now here's the problem, since we're reset to 1, if the code runs again it simply replaces "pic_camera2.png" again.
So what I need is for the code to recognize the last file created instead of the first one, or make index increase each time or something.