| 
 
| 
|  Author | Topic: Openin and Openout  (Read 602 times) |  |  
| 
| 
| IffySnuffy New Member
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 6
 
 | 
|  | Openin and Openout « Thread started 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
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| rtr2 Guest
 
 | 
|  | Re: Openin and Openout « Reply #1 on: Mar 13th, 2015, 9:02pm »
 |  |  on Mar 13th, 2015, 8:24pm, IffySnuffy  wrote:
 | | when I examine this file with notepad, the file is empty. | 
 | 
 This is what you wanted, I think:
 
 Code:
       highscore% = 500
      my_top_score% = OPENOUT(@usr$+"myscore.dat")
      PRINT #my_top_score%, highscore%
      CLOSE #my_top_score% Quote:
 | | how can I load the file back into my prog. | 
 | 
 For example:
 
 Code:
       my_top_score% = OPENIN(@usr$+"myscore.dat")
      INPUT #my_top_score%, highscore%
      CLOSE #my_top_score% Richard.
 
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| IffySnuffy New Member
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 6
 
 | 
|  | Re: Openin and Openout « Reply #2 on: Mar 13th, 2015, 10:16pm »
 |  |  Thanks Richard, that works a treat.
 Least I was part way there
   |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| IffySnuffy New Member
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 6
 
 | 
|  | Re: Openin and Openout « Reply #3 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$
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| rtr2 Guest
 
 | 
|  | Re: Openin and Openout « Reply #4 on: Mar 15th, 2015, 10:52pm »
 |  |  on Mar 15th, 2015, 10:12pm, IffySnuffy  wrote:
 | | 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.
 
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| IffySnuffy New Member
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 6
 
 | 
|  | Re: Openin and Openout « Reply #5 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
 |  
| 
|  |  Logged |  
 |  |  |  
 |