Destruction Productions
Destruction Productions
Destruction Productions
Would you like to react to this message? Create an account in a few clicks or log in to continue.


Make Games. Make Money. Make Friends.
 
HomeLatest imagesRegisterLog in

 

 Save the current level

Go down 
3 posters
AuthorMessage
gullesnuffs

gullesnuffs


Number of posts : 252
Registration date : 2009-05-06
Age : 30
Location : Stockholm, Sweden

Save the current level Empty
PostSubject: Save the current level   Save the current level EmptySun Nov 15, 2009 5:50 pm

It doesn't have to be more advanced than this, execute_file() isn't so slow that it can't be used and the file size really doesn't matter much, it probably won't be bigger than 5 kB.

Code:
{
 var i, j, object_number, object, file, str, n;
 //object_number=the number of different objects to be saved
 object_number=2;
 //here specify which objects are going to be saved
 object[0]=obj_player;
 object[1]=obj_enemy;
 file=file_text_open_write("map_00.xxx");
 str="var i;";
 for(i=0; i < object_number; i += 1)
 {
    for(j=0; j < instance_number(object[i]); j += 1)
    {
        n=instance_find(object[0], j);
        str += "i=instance_create(" + string(object[i]) + ", " + string(n.x) + ", " + string(n.y) + ");"
        + "i.other_variable=" + string(n.other_variable) + ";";
        //The other_variable is whatever else we want to save for this instance,
        //a if(object[i] == obj_enemy)save this variable else don't save it.
    }
 }
 file_text_write_string(file, str);
 file_text_close(file);
}

and the result for my sample level:

Code:
var i;i=instance_create(1, 176, 48);i.other_variable=3.65;i=instance_create(1, 96, 208);i.other_variable=0.54;i=instance_create(1, 240, 240);i.other_variable=3.44;i=instance_create(2, 176, 48);i.other_variable=3.65;i=instance_create(2, 96, 208);i.other_variable=0.54;

then it's just to execute the file when we want this new level to be loaded.
Back to top Go down
http://gullesnuffs.deviantart.com/
Hegemege
Moderator
Hegemege


Number of posts : 919
Registration date : 2009-02-21
Age : 31
Location : Helsinki, Finland

Save the current level Empty
PostSubject: Re: Save the current level   Save the current level EmptySun Nov 15, 2009 6:06 pm

Well done. So now we just need a level editor, which cant be really done yet.
Back to top Go down
Nragemachine

Nragemachine


Number of posts : 296
Registration date : 2009-02-25
Location : Illinois

Save the current level Empty
PostSubject: Re: Save the current level   Save the current level EmptyTue Nov 17, 2009 3:47 am

Very good, I'm glad to see you contributing Gulesnuffs, keep up the fine work! Very Happy
Back to top Go down
http://www.freewebs.com/nragemachine/guitarwarriorsforum.htm
Sponsored content





Save the current level Empty
PostSubject: Re: Save the current level   Save the current level Empty

Back to top Go down
 
Save the current level
Back to top 
Page 1 of 1
 Similar topics
-
» Planning For Level 1
» Level structure.

Permissions in this forum:You cannot reply to topics in this forum
Destruction Productions :: Archives-
Jump to: