Numbering screenshots

Started by GarageGothic, Mon 24/01/2005 12:41:46

Previous topic - Next topic

GarageGothic

I've been trying to find a way to auto-assign file names to screenshots, to prevent them from overwriting eachother. Currently I'm using the RawTime-feature and the StrCat command (not sure, I'm writing this from memory as I'm not at my own computer), so the screenshots are titled SP11004309.pcx and similar. This allows the user to save a screenshot every second without overwriting previous ones. And it works great. But it's not all that pretty. So I'm wondering, is there some other way to do it?

Some things I've considered and decided against:

1) Using the date and time to name them. While the number wouldn't appear as arbitrary as the rawtime number, the file name would be even longer than it is now (if using ddmmyyhhmmss format) and as the file already has its own date, the information is redundant for the player.

2) Using an external file to store the number of screenshots taken and assign n+1 to the next name. This would allow sequential numbering, but if the player deleted/moved the savegames, the next screenshots taken would continue the original sequence rather than restarting at 0.

SO, instead I'm wondering, is there any way at all to check the directory for existing files and continue the sequence (so if SP0009.PCX is found,  the new screenshot will be titled SP0010.PCX). I know how to do this for savegames, but not sure how to do it with other files.

jetlag

Use int filecheck=FileOpen("file.pcx",FILE_READ);
If filecheck is 0 then the file doesn't exist.

Code: ags

int time=GetRawTime();
string filename;
StrFormat (filename, "%d.pcx", time);
int filecheck=FileOpen(filename,FILE_READ);
if(filecheck==0){
  //create picture file
}
else{  //file excists already
  //panic
}
FileClose(filecheck);

GarageGothic

#2
Thanks for the suggestion. It's partly helpful, but:

I really suck at reading other people's code (I had to write my save game with screenshots system from scratch, because I didn't understand what was going on in the template script) but as I see it, you're still using rawtime to name the file here, and just checking whether it exists or not before writing. This is basically how it works now (and since rawtime is different every second there's no real need to check for overwrite).

What I was trying to do was to name the files sequentially ("SP0001.pcx", "SP0002.pcx" etc.) and have the script check the existing files for the highest number to continue the sequence (even after restarting the game).Ã,  It seems what I need is a script that checks through the numbers of the existing files by trying to open them, adding 1 to the end number for each try. How can I do this without running a repeatedly executing script? (And without manually checking for each possible file name :)).

Ashen

#3
If you don't like reading other people's code, you'll hate this one.....

(Adapted from jetlag's code)
Code: ags

Ã,  int seq = 0; // or whatever you want the lowest 'SP000x' to be
Ã,  string filename;
Ã,  StrFormat (filename, "SP%04d.pcx", seq); // Format the filename as you wanted - 'SP000x.pcx'.
Ã,  int filecheck = FileOpen(filename,FILE_READ);
Ã,  while (filecheck != 0){
Ã,  Ã,  Ã, FileClose(filecheck);Ã,  Ã,  
Ã,  Ã,  Ã, seq ++;
Ã,  Ã,  Ã, StrFormat (filename, "SP%04d.pcx", seq);
Ã,  Ã,  Ã, filecheck = FileOpen(filename,FILE_READ);
Ã,  Ã,  Ã, // File name exists, so add one and try again....
Ã,  Ã,  Ã, // Repeat until filename doesn't exist....
Ã,  }
Ã,  SaveScreenShot (filename); // then, save with that filename.


Is this more what you want? I'm sure there's a more streamlined way, but this one works for me.

EDIT: Just noticed that if you have, for example, SP000.pcx, SP001.pcx, SP002.pcx, SP003.pcx then you delete SP001.pcx, the next screenshot you take will fill that gap, rather than becoming SP004.pcx (if that makes any sense). Does that work for or against point 2 in the original post?
I know what you're thinking ... Don't think that.

GarageGothic

This looks like it would do the trick! Thank you very much Ashen. I'll try it out when I get home.

SMF spam blocked by CleanTalk