Colobot Forum - International Colobot Community

Full Version: How do I read a file in Cbot?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Say I'd like to read a line from a file.
Code:, mode);
s = file.readln();
What directory is checked for said file?
SatCom claims it's "files/" directory. Where is that exactly?
Can I access a specific line within that file?
In original Colobot it was "files/" directory inside the game installation directory. In Gold, for proper multiplatform support, it's stored along with the savegame files somewhere in user's home directory, meaning C:\Users\<username>\colobot\files on Windows or ~/.local/share/colobot/files/ on Linux. I guess we never updated SatCom to mention that.

To access a specific line, you have to loop over all the ignored ones that are before it, there is no other way as far as I'm aware. It's been a while since I used files in CBOT though.
We could probably use seek() and tell() methods in CBot. What do you think?
If the file contains Windows EOL (CR+NL) there's an additional question mark printed at the end of each line. (where the CR is)

If I have a custom level with bots reading files it would be nice if I could read one from the level directory. Otherwise installing user levels requires an additional step of dumping stuff in "colobot/files/"