Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I read a file in Cbot?
#1
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?
#2
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.
#3
We could probably use seek() and tell() methods in CBot. What do you think?
"After three days without programming, life becomes meaningless."
~The Tao of Programming
#4
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/"
#5
See issue #446


Forum Jump:


Users browsing this thread: 3 Guest(s)