BBC BASIC for Windows
« Openin and Openout »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:53pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Openin and Openout  (Read 602 times)
IffySnuffy
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx 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
User IP Logged

rtr2
Guest
xx 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.
User IP Logged

IffySnuffy
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx Re: Openin and Openout
« Reply #2 on: Mar 13th, 2015, 10:16pm »

Thanks Richard, that works a treat.
Least I was part way there smiley
User IP Logged

IffySnuffy
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx 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$
User IP Logged

rtr2
Guest
xx 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.
User IP Logged

IffySnuffy
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx 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
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls