Computer Science Canada Help with eof |
Author: | chipanpriest [ Wed Jan 11, 2012 5:59 pm ] | ||||||
Post subject: | Help with eof | ||||||
Hey guys. I'm making a game that stores a high score onto a text file and I need some help. Now, I do have basic understanding of open, close, put, get, seek so I'm not entirely lost. The code I am using is similar to this:
The error says it is attempting to read past the end of file (eof) and I understand what the problem is. There is nothing in the text file so it cant get anything out of it. What I need help with is if somebody could tell be how I could get the program to ignore the get statement if there is nothing in the text file. Any help will be greatly appreciated! I aim to have something like this:
EDIT I fixed the problem I was having but I ran into another one. Now when I exit the program, it doesn't save the highscore to my text file even though I told it to. This is the code I'm using:
|
Author: | chipanpriest [ Wed Jan 11, 2012 6:09 pm ] |
Post subject: | Re: Help with eof |
When I exit the program and start it back up, my highscore is reset and I was curious as to why so I opened up my text file and there was nothing in it! Yet you even saw the code I posted. Should it not put my highscore into the text file?? |
Author: | Tony [ Wed Jan 11, 2012 6:13 pm ] | ||
Post subject: | RE:Help with eof | ||
sorry, my post was in reply to before your edit, so I deleted it. Do you know that your code even tries to write anything? You can check for what with
Maybe your if-conditions are not true? Also, it seems that the file will hold at most one value. In which case you are not using mod, seek options. |
Author: | chipanpriest [ Wed Jan 11, 2012 6:17 pm ] | ||
Post subject: | Re: Help with eof | ||
Here, maybe you aren't getting enough code to judge if there is a problem or not. Ill post more code and I'll just attach the file.
|
Author: | Dreadnought [ Wed Jan 11, 2012 6:32 pm ] | ||
Post subject: | Re: Help with eof | ||
This
You said you wanted to make sure a highscores file exists (edit: I felt that was what you wanted to do). Read up on the File module, it has just what you need. |
Author: | chipanpriest [ Wed Jan 11, 2012 9:44 pm ] |
Post subject: | RE:Help with eof |
ooohhhhh thanks so much i didnt know that erased it haha xD |
Author: | chipanpriest [ Wed Jan 11, 2012 9:49 pm ] | ||||
Post subject: | Re: Help with eof | ||||
Yea! It works now guys! Thanks dreadnaught all i did was change this:
to this:
|
Author: | Alex C. [ Wed Jan 11, 2012 10:00 pm ] |
Post subject: | RE:Help with eof |
using the same idea, is it possible to create a save file for a game? |
Author: | Tony [ Wed Jan 11, 2012 11:27 pm ] |
Post subject: | RE:Help with eof |
Yes. The only difference is that instead of a single value, you'd write enough to reconstruct the state of the game. |
Author: | chipanpriest [ Thu Jan 12, 2012 7:03 am ] |
Post subject: | Re: Help with eof |
Does turing allow you to encrypt saved files into the program file? Or am I going to need a separate text file for every game i decide to have a save for? |