SOLVED Save Multiple Surfaces With Different Names At Once ???

M. Idrees

Member
Hi,
I want to save multiple surfaces at once in a loop but it doesn't working or I am doing it in a wrong way.
My code for saving the surfaces
GML:
if ( SAVE ){

    location = get_save_filename("PNG Sequence|*.png", "filename" );  // eg location = "\temp\images\ball.png"
    len = 0;

    if ( location != "" ){
        for ( i=0; i<ds_list_size(AREA); i++ ){

            surf = ds_list_find_value( AREA, i );
   
            draw_surface( surf, AREA_X1, AREA_Y1 );

            if ( i == 0 ){
   
                location = string_copy( location, 0, string_length(location)-4 ) + string(i) + ".png";   // eg at i = 0 [ location = "\temp\images\ball"  + "0" + ".png" ] and so on to the end of the loop
                len = string_length(location);
            } else {
   
                location = string_copy( location, 0, len-5 ) + string(i) + ".png";  // eg at i = 1 [ location = "\temp\images\ball"  + "1" + ".png" ] and so on to the end of the loop
            }
   
            if ( surface_exists( surf ) ){

                surface_save( surf, location ); // eg at i = 1 [ location = "\temp\images\ball1.png" ] and so on to the end of the loop
            }
        }
    }
}
It works if I don't change the filename string.

Thanks for your attention.
 
Last edited:

FoxyOfJungle

Kazan Games
Do you want to save multiple screenshots for multiple areas? I think you could add a variable in this line, like this:
surface_save( surf, location +string(number) +string(".png"));
I am giving the idea, you can test this way..
 

M. Idrees

Member
Do you want to save multiple screenshots for multiple areas? I think you could add a variable in this line, like this:
surface_save( surf, location +string(number) +string(".png"));
I am giving the idea, you can test this way..
No I just want to save them in the same area but with different names.

If I save the surface without changing the location then It works ( saves only the last surface in the loop because names are same ) but the moment I change the location string and replace name with different one then It doesn't work, Saving nothing.

I just want to achieve that ' Save multiple surfaces/sprites at ones but with different names At same location '
just taking the location at first with
GML:
location = get_save_filename("PNG Sequence|*.png", "filename" );
and then changing the name in the location string and saving another surface in the same location but with new name that I changed.

It also really hard for me to explain this but I think you got it.
 

FoxyOfJungle

Kazan Games
Areas I referred to were screen areas.

I have this script that adds a number to the end of the file with the same name, it might be useful for you, modify as you wish:
GML:
var _filename = "filename_";
var _extension = ".txt";

var _n = -1;
do
{
    _n += 1;
}
until
!file_exists(string(_filename)+string(_n)+string(_extension))

_f = file_text_open_write(string(_filename)+string(_n)+string(_extension));
repeat(10)
{
    var _random_number = random(999);
    file_text_write_string(_f, _random_number);
    file_text_writeln(_f);
}
file_text_close(_f);
 

M. Idrees

Member
I really appreciate your help.
Actually, I am saving surfaces not text files and surface can be saved with surface_save( filename ) function only, I think.
And I am taking location from the user which can be saved in a variable.
If, I save the surface with the location that the user selected its works but only save one file at a time but the moment I change the location and put a different name in it
Then, It doesn't work ? Saves nothing.

Area is a ds_list which stores all the surfaces that I have created.
 
Have you disabled sandboxing? GMS will not let you access files outside of working_directory without doing so, unless the user selects a specific file and even then you can only access that one file.

1599123946874.png
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
It doesn't work because you need to get permission for EACH AND EVERY FILE. The function get_save_filename() works once because the first file is flagged as accessible to the engine, but the next file you try to save hasn't been flagged by the function.
 

M. Idrees

Member
It doesn't work because you need to get permission for EACH AND EVERY FILE. The function get_save_filename() works once because the first file is flagged as accessible to the engine, but the next file you try to save hasn't been flagged by the function.
Then whats the solution for it or there is no solution ?
 
Ah ok, you might be out of luck without updating to 2.2.3+

The only way around for versions before that is to ask the user for permission for each file saved, rather than asking once and then trying to save all the files.
 

M. Idrees

Member
Hey I got It working manually by this code
GML:
/// SAVE ANIMATION

if ( SAVE ){
      
    location = get_save_filename("PNG Sequence|*.png", "filename" );
  
    name = filename_name( location );
    name = string_copy( name, 0, string_length(name)-4 );
    len = string_length( name );
  
    if ( location != "" ){
  
        for ( i=0; i<ds_list_size(AREA); i++ ){
      
            surf = ds_list_find_value( AREA, i );
          
            draw_surface( surf, AREA_X1, AREA_Y1 );

            if ( i != 0 ) {
              
                location = get_save_filename("PNG Sequence|*.png;*.jpeg;*.jpg", string_copy( name, 0, len ) + string(i) + ".png" );
            }
            keyboard_key_press( vk_enter );
          
            if ( surface_exists( surf ) ){
          
                surface_save( surf, location );
            }
        }
        show_message( "Image Sequence Saved Sucessfully" );
    } else {
  
        show_message( "Image Sequence Not Saved" );
    }
}
You just need to trigger the keyboard_key_press(vk_enter) to close the open dialog manually.
 
Top