BBC BASIC for Windows
Programming >> BBC BASIC language >> Openin and Openout http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1426278279 Openin and Openout
Post by IffySnuffy on Mar 13th, 2015, 8:24pm
Hi Could someone help me please. I have written a game which ends up with a highscore. I'm trying to write this highscore to disc, and then load it again next time I play the game, to try and improve on my highscore. Assuming my highscore was 500, I have written the following which saves a file within the 'My Documents' folder called 'myscore.dat' but when I examine this file with notepad, the file is empty.
my_top_score% = 500 my_top_score% = openout(@usr$+"myscore.dat") close #my_top_score%
Also, assuming I can save it with the highscore of 500, how can I load the file back into my prog. Would I use the openin command, and if so, how would I do that
Thanks very much for your help
Re: Openin and Openout
Post by rtr2 on Mar 13th, 2015, 9:02pm
my_top_score% = OPENIN(@usr$+"myscore.dat")
INPUT #my_top_score%, highscore%
CLOSE #my_top_score%
Richard. Re: Openin and Openout
Post by IffySnuffy on Mar 13th, 2015, 10:16pm
Thanks Richard, that works a treat. Least I was part way there Re: Openin and Openout
Post by IffySnuffy on Mar 15th, 2015, 10:12pm
Just one more point. I've managed to save the players name to file, in addition to the high score. What I was hoping for was to save the date too. I tried the following but just got a 'No such variable' instead of 'Sunday 15 March 2015' Thanks INSTALL @lib$+"DATELIB" date$ = FN_date$(mjd%, "dddd d MMMM yyyy") PRINT date$
Re: Openin and Openout
Post by rtr2 on Mar 15th, 2015, 10:52pm
I tried the following but just got a 'No such variable'
Well, yes, if that's the entire code then mjd% was indeed never defined, so that error is to be expected!
Do you really care about the date format? If you are prepared to use the default format that TIME$ delivers then LEFT$(TIME$,15) is a lot easier than messing about with DATELIB.
Richard. Re: Openin and Openout
Post by IffySnuffy on Mar 15th, 2015, 11:25pm
Oops, silly me. I looked up TIME in the help file, saw it wasn't what I was looking for, but missed TIME$ altogether I'm more than happy with LEFT$(TIME$,15). I guess I thought the mjd% bit was already pre-defined. Thanks