• 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.

Question - Code Loading from a file help

D

Deeo

Guest
Trying to just see if my game loads a text file and if there's info in it.

The file has several strings broken up by commas but i keep getting -1 from file_text_open_read.

heres my code:

Code:
var file_food_name = "foods.txt"; //Name of the file of the master list of foods in game and their attributes
file_food = file_text_open_read(working_directory + "\data\files" + file_food_name);

if (file_food = -1)
{
    show_message("Error! No information to load, CODE 21");
    exit;
}
game maker 1 tutorials so that (working_directory + "\data\files" + file_food_name) part should have a \ at the end of it but in GM2 it just makes everything else after the \" all text. Can't figure this out please help!
 
P

psyke

Guest
The "\" was changed in GMS 2, so to use that character you have to type: "\\".

Try this instead:
Code:
\\data\\files\\
 
D

Deeo

Guest
Still not working, just to make sure i'm doing this right where is the working directory? and anyway i can point it to load from my project folder ?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
The file HAS to be included in the project as an Included FIle in the resource tree. You also probably don't need "working_directory" (I never use it)... Also, (and this is probably the root of the issue) the code you posted is missing the "\" after "files". ;)

So:

Code:
file_food = file_text_open_read("\data\files\" + file_food_name);
 
D

Deeo

Guest
This seems so confusing to me, i can add it to the incluced file section of the resource tree but it just moves it to its own folder and i know have to edit the file from there and not the folder i want it in :(

Also file_food = file_text_open_read("\data\files\" + file_food_name); doesn't work cause in GM2 it just makes every thing after the \ show as strings.

and having it in the resource tree and doing file_food = file_text_open_read("\\data\\files\\" + file_food_name); doesn't load it either :(
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Ah, yeah, okay! Do this:

Code:
file_food = file_text_open_read(working_directory + @"\data\files\" + file_food_name);
And make sure the included files look like this:

upload_2017-2-5_23-16-38.png

That image is from the test I just did and works fine. My test code is simply this:

Code:
file_text = "test_test_test.txt";
file = file_text_open_read(working_directory + @"\Data\Test_Folder\" + file_text);
show_debug_message(file);
 
D

Deeo

Guest
Ah ok, the folders had to be were included files puts the file, that was the problem i was having.

Thanks alot, none of the documentation mention this.

It works now !!!
 
Top