• 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!

Save rooms created in in-game level editor

S

Simulacron

Guest
Hi, I want to create a level editor for my game to make it easier for myself to create levels for my game and also allow other people creating new levels for them. But when I'm done creating my level in my self programmed editor, how do I save it?
I saw that some people propose to use a diagramm out of numbers and letters, that saved every grid position of the room, to load it into a new one.
For example:
Code:
111111
1P0001
100001
100E01
111111

In my example 1 is a solid block, 0 is nothing, P is the obj_player and E is the enemy
My problem is that I don't really now how to save these informations and how to use them if the room gets loaded.

Another idea that I had was creating the room in the editor and saving the hole level as a new room. But is this even possible?

In short, I'm not sure what's the best way to store level data and acess it later, that was created in a level editor made in-game.
Thanks for your help!
 

nesrocks

Member
If you want the information to be saved between sessions you need to use the file saving functions. As for data structure, the example provided works. It all comes down to how you plan it for your own use.
 
S

Simulacron

Guest
If you want the information to be saved between sessions you need to use the file saving functions. As for data structure, the example provided works. It all comes down to how you plan it for your own use.
So I could save a new room with the saving functions?
 
N

Never Mind

Guest
It depends on what your trying to save:
game_save
NOTE:
This function is
very limited and it is designed for the beginner to get a save system up and running quickly, but more advanced users may prefer to code their own system using the File functions, due to the fact that the game will not save any of the dynamic resources like data structures, surfaces, added backgrounds and sprites etc..
 
S

Simulacron

Guest
While this all helps me to understand how to save my game, I'm still not sure how to set up a working saving/loading system of my level structure. Could abyone explain me how to set this up, maybe with the example above?
 
B

Blazing

Guest
Use ds_grid_create() and make a ds_grid the size of the room. Every time a user places an object, add that object's name,x,and y to the ds_grid. When the user saves, use the external text file functions to save and load, using ds_grid_write and ds_grid_read.
 

dphsw

Member
Personally I put all the variables (including some that are in ds_grids, in which case you have to take each value from the grid) into one big buffer, and then use the encode_base64 function. The resulting string can then be stored in a file, or in the GML code, or copied to the clipboard if it's a Windows executable, or could in principle be sent to a database, so there's plenty of options for how to load or save it once you've written code to convert to and from that format.
 
S

Simulacron

Guest
Thanks for your help! With these informations I (hopefully) will be able to create a working saving programm.
 
S

Simulacron

Guest
Use ds_grid_create() and make a ds_grid the size of the room. Every time a user places an object, add that object's name,x,and y to the ds_grid. When the user saves, use the external text file functions to save and load, using ds_grid_write and ds_grid_read.
I followed your ideas, but I still have one little problem. If I use the ds_grid_read command my grid gets loaded, but how can I now go through each cell, check if something is stored in there and if it is, place the according object.
 

NazGhuL

NazTaiL
The simplest way is to store using number:
0 - wall
1 - floor
2 - player
3 - Snake
4 - Ladder
etc...
Then you loop through each cell and use a switch

switch(number)
case 0: instance_create(wall...)
case 1: instance_create(player...)
etc...
-edit-
A better way will be to store the object_index
 
S

Simulacron

Guest
The simplest way is to store using number:
0 - wall
1 - floor
2 - player
3 - Snake
4 - Ladder
etc...
Then you loop through each cell and use a switch

switch(number)
case 0: instance_create(wall...)
case 1: instance_create(player...)
etc...
-edit-
A better way will be to store the object_index
But how do I get from cell to cell? Doens't your code just checks one cell and stops then?
 

NazGhuL

NazTaiL
huh... for loops? Thats basics... :)

Code:
var xx, yy, value;
var grid = your_grid.
var gw = ds_grid_width(grid);
var gh = ds_grid_height(grid);

for(yy=0; yy<gh; yy++)
{
     for(xx=0; xx<gw; xx++)
     {
     value = ds_grid_get(grid, xx,yy);
     switch here
     }
}
 
S

Simulacron

Guest
huh... for loops? Thats basics... :)

Code:
var xx, yy, value;
var grid = your_grid.
var gw = ds_grid_width(grid);
var gh = ds_grid_height(grid);

for(yy=0; yy<gh; yy++)
{
     for(xx=0; xx<gw; xx++)
     {
     value = ds_grid_get(grid, xx,yy);
     switch here
     }
}
Thanks for your help. I think I really need to learn all loops :rolleyes:
 
Top