|
« on: July 03, 2009, 05:35:42 am »
|
|
I've been trying to make it work for the entire day,but I can't seem to find the problem. Basically, I want to load all objects, backgrounds, etc. from a text file.It work pretty well... for the background and music. It's probably a logic error, but I can't figure it out. The script replace all objects with the last one: The thing is; the position of each object is correct, but it's the wrong one I tried 2 version, both version fail the same way. General part of the code: // Load level through text files // only one argument--> argument0 == name of the level/text file
var level, L, line, music, i, obj;
if !file_exists(working_directory+"\levels\"+argument0+".txt") return 0 level = file_text_open_read(working_directory+"\levels\"+argument0+".txt"); // Store each line of the file in one array entry
L=0; while !file_text_eof(level) { line[L]=file_text_read_string(level); // copy the line into the array file_text_readln(level); // skip to next line when done L += 1; } file_text_close(level);
text file for version 1 1240 line[0] room width 480 line[1] room height TestBackground.bmp line[2] background secretinvasion.mp3 line[3] song 3 line[4] number of object to create 320 line[5] x position of object1 360 line[6] y position of object1 obj_ground1 line[7] name of object1 895 line[8] x position of object2 357 line[9] y position of object2 obj_ground2 line[10] name of object3 400 line[11] x position of object3 380 line[12] y position of object3 obj_hero_R line[13] name of object3 Version 1 // object
if ( real(line[4]) > 0 ) // if need to create object { i = 5; // start at line 5 while ( i < 5 + ( real(line[4]) * 3) ) // ( 5 + real(line[4]) * 3 ) == max number of lines + 1 { instance_create(real(line[i]), real(line[i+1]), line[i+2]); i += 3; } } text file for version 2 1240 line[0] room width 480 line[1] room height TestBackground.bmp line[2] background secretinvasion.mp3 line[3] song 3 line[4] number of object to create 320,360|obj_ground1 line[5] object1 895,357|obj_ground2 line[6] object2 400,380|obj_hero_R line[7] object3 Version 2 // object
if ( real(line[4]) > 0 ) // line[4] == number of object to create { i = 5; while ( i < 5 + real(line[4]) ) { // find the position of the separators oba = string_pos("," , line[i]); obb = string_pos("|" , line[i]); // use that info to split the string and store the part into an array obj[0] = string_copy( line[i], 1, real(oba)-1); // copy the Xpos of the object obj[1] = string_copy( line[i], real(oba) + 1, real(obb) - (real(oba) + 1 )); // copy the Ypos of the object obj[2] = string_copy( line[i], real(obb) + 1, real(string_length(line[i])) - real(obb)); // copy the name of the object // create the instance instance_create(real(obj[0]), real(obj[1]), obj[2]); i += 1; } } And that's pretty much it! Anyway, if someone could help me, I would be really grateful...
Logged
|
Rome wasn't built in a day, but they didn't waste time by sitting around doing nothing either!
|