Legacy GM [SOLVED] sprite_save is not saving sprites

Antikore

Member
I'm actually making a game. When you play it, at the start, a starting code runs for creating base files and stuff that will be needed when you're in the game.
While all things work properly I think, the part that I save a few sprites to one of the folders isn't working.
These files are saved on a previously empty folder, then they will be loaded by a list, and the game runs.
All except the first thing works. I've tried to search on the forums and I haven't found anything, the game still runs, and the menu takes some of those images, but as these images aren't saved, all shows up a black sprite.

Code:
Code:
if (!directory_exists(working_directory+"saves\characters"))
{
    directory_create(working_directory+"saves\characters");
    if (!file_exists(working_directory+"saves\characters\blue_block.png"))
    {
        sprite_save(spr_blue_block,0,working_directory+"saves\characters\blue_block.png");
    }
    if (!file_exists(working_directory+"saves\characters\red_block.png"))
    {
        sprite_save(spr_red_block,0,working_directory+"saves\characters\red_block.png");
    }
}
obj_startup_controller - create event - executed in the first room of all the game run.

What I've tried:
  • I found some lexical issues on the directory, I corrected them, they don't fixed the problem.
  • I read the docs, sprite_save() and should work like this (I think).
  • I've tried to remove the .png part from the file name, as the sprite_save only saves png, I thought might work, but it doesn't work.
  • I removed the folders, obviously, multiple times, as this is only executed if the folder wasn't created yet.
  • I searched on the directory, and yes, no files were in the folder.
Technical Information:
  • Windows 10
  • GM: Studio v1.4.1804 Standard Edition
Thank you for reading :D
 
sprite_save() seems to only work with dynamically created sprites, possibly a bug or missing information from the manual:

The function sprite_save() does not work with sprites created previously in the game.
It only works with dynamically created ones.

This should be specified in the documentation.

But there is an easy solution to do it:

sprite_variable=sprite_duplicate(sprite_name_not_string);
sprite_save(sprite_variable, 0, "name.png");

Remember to include the image index in the second parameter
https://forum.yoyogames.com/index.p...d-no-bitmap-data-available.65928/#post-396999

https://forum.yoyogames.com/index.php?threads/sprite_save-no-bitmap-data-available-solution.66382/
 
You're welcome.

Just in case someone else finds this thread, I'll just add this note from the manual that the duplicated sprite should be deleted to prevent memory leaks:

NOTE: When you duplicate a sprite in GameMaker Studio (1 or 2) you must remember to remove it again (with sprite_delete) when no longer needed, otherwise there is risk of a memory leak which will slow down and eventually crash your game.
 
Top