• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

importing text using a text file

A

asgloki

Guest
Hello everyone,

I have been trying to import text into my game because Im making an rpg style game with allot of items and dialogue but it dont seem to be working.
this is that im using: file = file_text_open_read(working_directory + "\level.txt");

i think the game cant find the file, anyone have any idea how to do this?
it seems to work if i create the file in the game but I need to be able to import data that I make externally.

I think it might have something to do with the sandboxing?

any help would be much appreciated.
 
A

asgloki

Guest
thats awesome and it works thank you kindly, now I just need to figure out how to read from a text file using coma or some other way to separate the data, for example.

name, age, occupation, etc.
 

chamaeleon

Member
thats awesome and it works thank you kindly, now I just need to figure out how to read from a text file using coma or some other way to separate the data, for example.

name, age, occupation, etc.
Use a combination of string_pos and string_copy to pick out the parts of the line. Maintain a current start position, find the position of the next comma (or a condition indicating you're at the last part when you don't find one), copy the part of the string, update the current start position, and repeat until done.
 
A

asgloki

Guest
thanks for the reply,

this is the code im using atm, its messy :-(
GML:
// isAString[0] = -1;
isAString[0] = 1;
isAString[1] = 0;
isAString[2] = 1;
isAString[3] = 0;
isAString[4] = 1;
isAString[5] = 0;
isAString[6] = 0;
isAString[7] = 0;
isAString[8] = 0;
isAString[9] = 0;
isAString[10] = 0;
isAString[11] = 0;


var i = 0;
file = file_text_open_read(working_directory + "\ITEMS.TXT");
file_text_readln(file);    // GOTO NEXT LINE
repeat(11)
{
    if (isAString[I] == 0)
        {
        scr[I] = file_text_read_real(file);       
        }         
            else if (isAString[I] == 1)
            {
            var theString = file_text_read_string(file);
            var length = string_length(theString);
            var ii = 1;
                repeat(length)
                {
                    var char = string_copy(theString, ii, 1);
                       if (char == "/")
                        {

                        break;
                        }
                            else
                            {
                            scr[I] = string_copy(theString, 1, ii);
                            ii ++;                                              
                            }
                            
                }

            } // END OF IS A STRING
            else
            {
            scr[I] = "WHAT TO DO ABOUT THIS";
            }
    i++;
    file_text_readln(file);    // GOTO NEXT LINE
}   
file_text_close(file);[/I][/I][/I][/I][/I]
within the document is text and real numbers so im trying to work out a way to separate them, that is why I created that array in the start but its a crap way to solve it, i need something more dymamic. Im also using per line not seperating with coma.
 
Last edited by a moderator:

FrostyCat

Redemption Seeker
Post your code between [code=gml] and [/code] tags. Your code contains [i], which the BBCode parser interprets as italics and ruins the rest of your post.
 
A

asgloki

Guest
now i am having a similar problem i was having in the start, getting the message that it cant find the file. Strange thing is that it finds the file if i create another project, but when i copy the exact same code over to my main project it then cant find the file, even though I used the included files.
 
Top