Destruction Productions


Make Games. Make Money. Make Friends.
 
HomeRegisterLog in

Share | 
 

 Save the current level

View previous topic View next topic Go down 
AuthorMessage
gullesnuffs

avatar

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

PostSubject: 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.

__________________
My band's MySpace http://www.myspace.com/koostumus
My deviant art http://gullesnuffs.deviantart.com/
Back to top Go down
http://gullesnuffs.deviantart.com/
Hegemege
Moderator
avatar

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

PostSubject: 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.

__________________
WTF = Welcome To Finland

"I'm a Finnish man. I eat iron and sh*t chains!"
Back to top Go down
Nragemachine

avatar

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

PostSubject: 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! Very Happy

__________________
Watch Awesome Videos!!
Back to top Go down
http://www.freewebs.com/nragemachine/guitarwarriorsforum.htm
Sponsored content




PostSubject: Re: Save the current level   

Back to top Go down
 
Save the current level
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» with the boom in construction is kapi worth at current level to buy?
» What about CSD @ current level?
» BUKI at current price level
» When CFA Level 1 (2011 June Exam ) result release?
» Some ideas about current market situation

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