File : read/write & error

Started by Cassiebsg, Sun 12/02/2017 18:58:10

Previous topic - Next topic

Cassiebsg

Okay, sorry if there's a a simple solution for this somewhere, but I just coded an entire achievements GUI for my game, it's working pretty decent too. :-D

Except that if there's an error on the file (like I edited using notepad and saved it), then game will crash. :-\
I'm not sure how to fix this either.

I'm not sure if there's a problem with output.WriteString also, but I couldn't get the "input.error" to work with the "buffer=input.ReadStringBack();"

if I put the if before the read, it does nothing, and then the game crashes once it reaches the read line (File.ReadStringBack: file was not written by WriteString). If I  put the if (input.error) after the read, the game crashes and never reaches the next line to execute the if. :-X

However in the manual it says "This function only checks for errors while actually reading/writing data." which seems to indicate that should work to also detect reading errors on the file... (roll)

So, am I doing this all wrong? Is the manual wrong? And can't AGS issue an error for devs to work with (like allowing me to delete the faulty file, create a new empty one and tell the player about the error?) instead of just crashing?

If there's no solution, I'll put a warning about not editing these .dat files on the readme/manual.txt (knowing nobody really reads these anymore) and if the player ignores the warning the solutions... as in "delete the file and start a new game". :P
There are those who believe that life here began out there...

Khris

If you want to use text files in AGS but also edit them outside of AGS, you have to use ReadRawChar / ReadRawLineBack and WriteRawChar / WriteRawLine.

Cassiebsg

Thanks, but no, I don't want them to be edited outside AGS, otherwise I would have used the IniFile module for this (which I am already using to keep track of in game user settings, and would have been easier to code).

All I want now is for the game not catastrophically crash, if the player does go an try to edit the files (or if they get corrupt somehow).
I specifically choose to use File:Read/Write, so the player can't easily just edit and change the values.
There are those who believe that life here began out there...

Khris

I see. AGS doesn't have any error handling like try ... catch, so the only option I can see is to

a) use Raw commands like I said
b) use some basic obfuscation technique to hide the data
c) check the data's integrity after reading it, and failing that, delete / reset the file

A user who opens the file won't see anything readable, and if they do mess with it, they lose their achievements. Win-win, basically.

SMF spam blocked by CleanTalk