Jump to content


Delphinus

Member Since 29 Apr 2012
Offline Last Active Apr 29 2012 10:23 PM

Posts I've Made

In Topic: file_exists functioning incorrectly

29 April 2012 - 05:32 PM

Directly above the snippet I already posted:

with(instance_find(Player,0)){
    y = (global.room_ySize*16)-10;
}

saveRoom();
global.room_y -= 1;

It updates. The problem, like I said in my edit above, is the loading script itself. Hopefully I can make it work, updates if I make any progress.

EDIT: Fixed, with a few small bugs. Everything is now perfectly persistent. I totally rewrote the loading code, but used the same principles as before. Here it is.

theX = argument0;
theY = argument1;


//get the file, read it into arrays of strings
fileId = file_text_open_read(working_directory + "\tempFiles\" + string(global.playId) + "_" + string(theX) + "_" + string(theY) + ".txt");
for(y1=0; y1<global.room_ySize; y1+=1){
        theString = file_text_read_string(fileId);
        theBaseStrings[y1] = theString;        
        file_text_readln(fileId);
}

file_text_readln(fileId);

for(y1=0; y1<global.room_ySize; y1+=1){
        theString = file_text_read_string(fileId);
        theOverlayStrings[y1] = theString;
        file_text_readln(fileId);
}

file_text_close(fileId);

//break up the strings, read into maps
for(y1=0; y1<global.room_ySize; y1+=1){
    x1 = 0;
    theTileString = "";
    for(stringPos=0; stringPos < string_length(theBaseStrings[y1]); stringPos+=1){
        theChar = string_char_at(theBaseStrings[y1],stringPos);
        if(theChar != ","){
            theTileString += theChar;
        }
        else{
            theTile = real(theTileString);
            global.baseMap[x1,y1] = theTile;
            theTileString = "";
            x1 += 1;
        }
    }
}

for(y1=0; y1<global.room_ySize; y1+=1){
    x1 = 0;
    theTileString = "";
    for(stringPos=0; stringPos < string_length(theOverlayStrings[y1]); stringPos+=1){
        theChar = string_char_at(theOverlayStrings[y1],stringPos);
        if(theChar != ","){
            theTileString += theChar;
        }
        else{
            theTile = real(theTileString);
            global.overlayMap[x1,y1] = theTile;
            theTileString = "";
            x1 += 1;
        }
    }
}

EDIT2: For the curious, the original reason for my problem was a combination of the filename thing and the fact I didn't insert the file_text_readln() function after I'd retrieved each line from my save file. This meant that it read to the end of the first line then gave up, loading only the top part of each screen and keeping the rest the same as any previous screen. Most of the other changes to the code were just to make it easier to understand and read.

In Topic: file_exists functioning incorrectly

29 April 2012 - 03:36 PM

working_directory + "\tempFiles" + string(global.playId) + "_" + string(global.room_x) + "_" + string(global.room_y) + ".txt"
working_directory + "\tempFiles\" + string(global.playId) + "_" + string(theX) + "_" + string(theY) + ".txt"

Comparing the two file strings, it looks like there is an extra "\" after "\tempFiles" in the second argument. Remove it and see if it works, if not try putting both arguments into "show_message()" to verify that they in fact do match.

[edit] lol lemon pie beat me by two seconds :P


That wouldn't work; the file path would be completely messed up. However, I did add an additional backslash into the former. By chance, I fixed the previous problem, only to find that when I'm trying to load a previous room, it just reprints the last room I was in. This suggests a problem with the load function rather than the code snippet that was the original problem.

EDIT: Using messages to debug makes it obvious that it's only loading the first row of the new room. This is probably something to do with my use of file_text_read_string(), or a misunderstanding of the way file reading works in GML. I'm used to the 'video-tape' file streaming of C++ or VB, but I'm probably way off mark trying to apply the same principles to a scripting language like GML.