gullesnuffs
Number of posts : 252 Registration date : 2009-05-06 Age : 30 Location : Stockholm, Sweden
| Subject: Save the current level Sun 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. | |
|
Hegemege Moderator
Number of posts : 919 Registration date : 2009-02-21 Age : 31 Location : Helsinki, Finland
| Subject: Re: Save the current level Sun Nov 15, 2009 6:06 pm | |
| Well done. So now we just need a level editor, which cant be really done yet. | |
|
Nragemachine
Number of posts : 296 Registration date : 2009-02-25 Location : Illinois
| Subject: Re: Save the current level Tue Nov 17, 2009 3:47 am | |
| Very good, I'm glad to see you contributing Gulesnuffs, keep up the fine work! | |
|
Sponsored content
| Subject: Re: Save the current level | |
| |
|