• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Saving a buffer

S

steveyg90

Guest
Hi,

I have the following code to save a ds_grid:

Code:
        buffer = ds_grid_write_buffer(tileList);
        show_debug_message(working_directory);
        ds_grid_dump(buffer);
        buffer_save(buffer,working_directory+"map1.sav");
But when I look for the saved file, it isn't there? Am I missing something? Is there any other way of saving these maps to local hard drive and not in the sandbox of GMS2? Do you need to add to the include files section?

Thanks
 

Binsk

Member
You can't get outside the sandbox. Simple as that. The one exception is on Windows only when using get_save_filename. For any other scenario you need an external library that doesn't care about the sandbox to write the files.

There are plenty of these on the marketplace or you can write an external library yourself (this kind of library is fairly trivial to make if you know what you are doing).
 
S

steveyg90

Guest
Yeah thought that. I would be fine to code up a library to do the writing - do you do these in C/C++ (never written an extension for GML before), I've been coding in C++ for over 10 years.
I just want to be able to save contents of ds_grid to a file and also read it back in.

Thanks
 

Binsk

Member
Yes, you can do it in c/c++ (for the big 3 anyway. Mobile and such is a bit different).

You just need to look up how to write functions that interface with GM in c/c++ and the rest is just regular programming.

You can get the address of a buffer in GM and pass it as a pointer to your library. Then just read it as you would an array and write it using whatever library you want.
 
S

steveyg90

Guest
Yeah was gonna look at doing that but found a neat extension(s) which does what I want and I like to support our fellow game devs ;-)

Extensions using are: nsfs and also GridBuffer - kudos to the authors of these.

My code is now:

Code:
        buffer = ds_grid_write_buffer(tileList);  // tileList is a ds_grid
        buffer_save_ns(buffer,"f:\map1.dat");
        unbuffer = buffer_load_ns("f:\map1.dat");
        bf = ds_grid_write(unbuffer);  // bf is now a ds_grid with the map data :-)
I won't hard code the drive path in when release, this is just for testing. I'm using this in my map editor I'm creating for my new game, so glad I got these extensions as save me some valuable time
from having to create them myself.
 
S

steveyg90

Guest
Hmmmm, the code I wrote before doesn't work when I am wanting to load back...doesn't look like it saves the ds_grid data?

To save I do:
Code:
        buffer = ds_grid_write_buffer(tileList);
        buffer_save_ns(tileList,"f:\map1.dat");
To load I do:
Code:
   buffer = buffer_load_ns("f:\map1.dat");   // <----- sometimes doesn't get converted to a ds_grid??? And when it does, always no data in there?
So, when loading, sometimes randomly the buffer cannot be viewed as a ds_grid, and when it can, it has no data so believing the buffer_save_ns hasn't worked.

Anybody any advice?

Thanks

** FIXED ** needed to put buffer = ds_grid_read_buffer(buffer) in the load code...
 
Last edited by a moderator:
Top