Menu

writing to file (again)

Anonymous
2017-05-19
2017-05-25
  • Anonymous

    Anonymous - 2017-05-19

    I've written a game based on the Tour of France and it's the nearest to a simulation I can do. BUT I can't save values fron one sessions to the next. So if I run say 6 stages one evening, the only way I can keep the changes is by leaving everything 'on' all night - if I turn thr computer off, the changes to the strings are lost - and I have to start at stage 1 again.

    I've made deperate pleas for help before and people have kindly replied but I've got a complate mental block on this as well as basic ignorance. Please could someone explain to me as they might explain to a child of 5, how I can save the content of a string whose values have been changes 'within the game' so these values replace the original ones and will still be there when I next turn everything on

    thanks

    Eric Walter

     
  • Anonymous

    Anonymous - 2017-05-23

    The program is really long and tortuous.An explanation is simpler.
    Say it's football game with 10 teams. All the teams would start off with no points so I'd have a line -
    dim pts(10):for f=1 to 10:read pts(f):next
    and a data line -
    data 0,0,0,0,0,0,0,0,0,0

    In the course of the evening, Swansea (say) might get (say) 11points.
    But then it's time for bed and I have to turn everything off and I'm onlypart way through the season!

    When I next load and run the program,Swansea (and everyone else) all are back with 0 points each. What I need is something so that when I next load and run, Swansea continue with from points

    Inspite of kind efforts to explain,I still haven't a clue!

    thanks
    Eric Walter

     
    • Anonymous

      Anonymous - 2017-05-24

      What you want to do is before you go to bed is call a save subroutine. When you are ready to resume play then you call a load subroutine. In your example you are trying to save the pts() array. Here is how you go about saving and loading it:

      10 FOR i=1 TO 10:READ pts(i):NEXT
      20 DATA 1,2,3,4,5,4,3,2,1,0
      30 'save points
      40 OPEN "o",#1,"pts.txt"
      50 FOR i=1 TO 10:PRINT #1,pts(i);:NEXT
      60 PRINT #1,
      70 CLOSE #1
      80 'erase points to prove they are saved
      90 ERASE pts
      100 'load points
      110 OPEN "i",#1,"pts.txt"
      120 FOR i=1 TO 10:INPUT #1,pts(i):NEXT
      130 CLOSE #1

       
  • Anonymous

    Anonymous - 2017-05-25

    Very many thanks Anonymous. I've been playing around with basic starting with Mallard Basic in abt.1985. Once, in abt. 1989, I managed to do it without any help - but the disc got damaged and it was lost forever. Since then I have tried and tried but I really have a mental block & I'm not clever enough to understand first principles. At the moment, I'm too nervous to try it out!!

    Eric Walter

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.