Colobot Forum - International Colobot Community
How do I read a file in Cbot? - Printable Version

+- Colobot Forum - International Colobot Community (https://colobot.info/forum)
+-- Forum: [Archive] New forum (2015-2019) (https://colobot.info/forum/forumdisplay.php?fid=76)
+--- Forum: Colobot: Gold Edition Basics (https://colobot.info/forum/forumdisplay.php?fid=58)
+---- Forum: Help (https://colobot.info/forum/forumdisplay.php?fid=61)
+---- Thread: How do I read a file in Cbot? (/showthread.php?tid=900)



How do I read a file in Cbot? - Mrocza - 03-04-2017

Say I'd like to read a line from a file.
Code:
file.open(filename, 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?


RE: How do I read a file in Cbot? - krzys_h - 03-04-2017

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.


RE: How do I read a file in Cbot? - tomaszkax86 - 03-04-2017

We could probably use seek() and tell() methods in CBot. What do you think?


RE: How do I read a file in Cbot? - Mrocza - 03-05-2017

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/"


RE: How do I read a file in Cbot? - krzys_h - 03-05-2017

See issue #446