ALLEGRO_FILE *file = al_fopen("level.txt", "wb"); if(file==0) { std::cout << "fail" << std::endl; }
Hello, I don't get why this outputs fail 
It should create a file for writing, right? Even if one doesn't exist?
So... what could possibly cause it to do that?
If it is a text file, you shouldn't use "wb", but "w" for text mode.
As for why it fails - you might not have write permission to the directory it is trying to create a file in.
You said you were using PhysFS, so what are you actually trying to write to? A zip file?
Show more code.
This should be all the code relevant for physfs (if I remember correctly):
I can't find other places that messes with file interfaces by searching. There shouldn't be any either.
I'm attempting to write to an ordinary folder. Or... actually I'm not sure. I'm writing to the root directory and considering the nature of physfs that could be several places. I think.
I still don't know what to do though.
Here's what I'm trying to do:
Try calling PHYSFS_init before calling al_set_physfs_file_interface.
Make sure your current working directory is correct, and make sure that the 'data' folder exists.
I tried doing as you suggested but it was still the same result.
I think my current working directory is wrong like you suggest actually. But I'm not sure how to set it or figure out what it is. The data dir exists - I'm already loading resources in and they are in that dir. I actually copy pasted the path originally.
Try al_set_standard_file_interface() before doing that.
If you're using gcc, you can use getcwd(const char* buffer , int buf_size); to check the current working directory.
A5 has functions to change the current working directory and find the full path to your executable.
See
al_get_standard_path
and
al_change_directory
If I call al_set_standard_file_interface() just before al_fopen then it DOES work, but the program crashes because I need PhysFS to display the font and graphics of the closing dialog I use (and basically everything with resources everywhere).
My problem indeed seems to be figuring out how to open a file for writing using the physfs file interface.
So I'm stuck again with this and don't know where to go from here:
Also a small change here...
/* Set up PhysicsFS. */ if(!PHYSFS_init(0)) std::cout << "failed initializing" << std::endl; else { al_set_standard_file_interface(); al_set_physfs_file_interface(); if(!PHYSFS_addToSearchPath("data", 1)) std::cout << "failed adding search path" << std::endl; if(!PHYSFS_addToSearchPath("lvl", 1)) std::cout << "failed adding search path2" << std::endl; }
EDIT:
DO I need to use this:
ALLEGRO_FILE *file = al_create_file_handle(al_get_new_file_interface(), 0);
?
I think you need to setup the main filesystem as a mount in PhysFS or you can't access the main filesystem. "Standard Path's" mean nothing in PhysFS if you don't have the filesystem "mounted".
You can switch back to the physfs interface at any time with al_set_physfs_file_interface();
... that's probably not ideal, something like Thomas said might work better, but I just switch back and forth as needed.
Alright I'll switch back and forth from interfaces until I learn how setting up mounts work. It wont be much of a problem in this case really.
Thanks very much for your comments/advice.