Project

General

Profile

Actions

Bug #249

open

File saving not working

Added by Paul Kitching over 4 years ago. Updated almost 3 years ago.

Status:
In Progress
Priority:
High
Target version:
-
Start date:
02/23/2020
Due date:
% Done:

0%

Estimated time:
24:00 h
Affected version:

Description

I can read files, but saving them doesn't work. There is no error message, but the file doesn't seem to go anywhere and can't be read back in.

#manifest:"pc"
#displayWidth:1920
#displayHeight:1080
#fullScreen:true
#splashScreen:false
#fps:false

dim  scoretable$(10,2)
for x=1 to 10
  scoretable$(x,1)="Empty":scoretable$(x,2)="0"
next x
gosub readfile
for x=1 to 10
  print scoretable$(x,1),scoretable$(x,2)
next x
end

readfile:
if exist("highscore.dat")
  print "found":wait key
  open in 1,"highscore.dat"
  for loadrow=1 to 10
    input #1,scoretable$(loadrow,1)
    input #1,scoretable$(loadrow,2)
  next loadrow
  close 1
else
  print "not found":wait key
  gosub writefile
  print "Re-run (f5) to load created file."
end if
return

writefile:
open out 1,"highscore.dat"
for saverow=1 to 10
  print #1,scoretable$(saverow,1)
  print #1,scoretable$(saverow,2)
next saverow
close 1
return

Actions #1

Updated by Paul Kitching over 4 years ago

  • Affected version changed from 0.9.5 to 0.9.7

I keep hearing that file saving is supposed to be working, but I've never been able to get any file to save and re-load.

This program still doesn't find the file. Even if you edit out the 'if exists' parts and just try to load it regardless, you get a file not found.

Actions #2

Updated by Laurant Weill about 4 years ago

  • Priority changed from Normal to High
Actions #3

Updated by Brian Flanagan about 4 years ago

  • Status changed from New to In Progress
  • Estimated time set to 24:00 h

This is working now, but probably not as you expect. Due to security restrictions, files are being saved to the web browser cache instead of the local application folder. The Exist function is not looking there at the moment, so yes, you will need to bypass that right now.

WARNING 1: Since files are now stored to the web browser cache, if you clear the browser cache, they'll be gone, so be careful of your browser's cache options!

WARNING 2: The browser's application: area is shared by ALL of your AOZ applications, so be aware that if you have the same filenames, your file for one application will be over-written by the other. (If game1 and game2 both have highscore.dat, you'll have problems. For now, just make sure you name them differently: game1_highscore.dat, game2_highscore.dat

We are working on a way to make it so we can save to the local application's folder, but for now, this is the work-around.

Actions #4

Updated by Brian Flanagan about 4 years ago

  • Affected version changed from 0.9.7 to Beta RC2

I modified your test program, and tested in in the current version: Beta RC2.

#manifest:"pc"
#displayWidth:1920
#displayHeight:1080
#fullScreen:true
#splashScreen:false
#fps:false

dim  scoretable$(10,2)
fn$= "highscore.dat"

Print Dir$
Print "------ (actually in browser cache)"
Dir
Print "------"
Print "Press any key to start."
Wait Key

// Create hiscores file
for x=1 to 10
  scoretable$(x,1)="Empty":scoretable$(x,2)=Str$(x)
next x
gosub writefile

// Show what we just created
Print "Created (or over-wrote)";fn$;", contents: "
gosub printtable
Print

// Clear the table before reading it back in.
for x=1 to 10
    scoretable$(x,1)="" : scoretable$(x,2)=""
next x
// Read the table back from the file.
gosub readfile
Print "Read ";fn$;" contents:"
gosub printtable
End

printtable:
for x=1 to 10
  print scoretable$(x,1),scoretable$(x,2)
next x
return

readfile:
// if exist("highscore.dat")
//  print "found":wait key
  open in 1,fn$
  for loadrow=1 to 10
    input #1,scoretable$(loadrow,1)
    input #1,scoretable$(loadrow,2)
  next loadrow
  close 1
  /*
else
  print "not found":wait key
  gosub writefile
  print "Re-run (f5) to load created file."
end if
*/
return

writefile:
open out 1,fn$
for saverow=1 to 10
  print #1,scoretable$(saverow,1)
  print #1,scoretable$(saverow,2)
next saverow
close 1
return
Actions #5

Updated by Brian Flanagan over 3 years ago

  • Assignee changed from Francois Lionet to Baptiste Bideaux
  • Affected version changed from Beta RC2 to 1.0.0 (B8)

Re-tested in 1.0.0 (B8) June 3.
Still fails.
Here's a simpler example:

Open Out 1,"MyFile.dat" ' Should open "MyFile.dat" on default file system.
    Print #1,"test" ' Gets File Not Opened error (ever after Open Out succeeds)
Close 1 ' Close also fails even after Open Out.
Dir ' Should show directory of default file system with "MyFile.dat" in it.

The above fails at Print #1
If that line is commented, then it fails at Close 1
My guess is therefore that probably (although no error was displayed), Open Out probably failed, or failed to do something it needed to to tell the other file commands that the file is open and ready for writing.

Actions #6

Updated by Paul Kitching about 3 years ago

This all seems to be working in Beta 10.
I can't change the status to closed while it's "In Progress"

Actions #7

Updated by malcolm harvey about 3 years ago

Brian Flanagan wrote in #note-5:

Re-tested in 1.0.0 (B8) June 3.
Still fails.
Here's a simpler example:

Open Out 1,"MyFile.dat" ' Should open "MyFile.dat" on default file system.
  Print #1,"test" ' Gets File Not Opened error (ever after Open Out succeeds)
Close 1 ' Close also fails even after Open Out.
Dir ' Should show directory of default file system with "MyFile.dat" in it.

The above fails at Print #1
If that line is commented, then it fails at Close 1
My guess is therefore that probably (although no error was displayed), Open Out probably failed, or failed to do something it needed to to tell the other file commands that the file is open and ready for writing.

I still find it wont write anything if the file exists or not in Beta 10 same as Brian.

Actions #8

Updated by malcolm harvey about 3 years ago

The Reading tho works fine from disk.
Note: I did test mine and pauls code again, (Pauls below) it does seam to
say as mine it reads and writes ok but, writing where ok if its working
then it is working in browser cache/memory ok as paul confirms in vivaldi https://discord.com/channels/653893653940404224/777642924275400715/893549838438924298
but yeah not to real disk at all still at this point.
(Nothing writes from application but as brian points out above still that is wip).

..
#splashScreen:false
print "Current directory:";dir$
Open Out 1,"test.txt"
Input "Please enter your name ";name$
Print #1,name$
Close 1
print "File written, now reading..."
name$="blank"
Open In 1,"test.txt"
Input #1,name$
Print "Hello ";name$
Close 1

Actions #9

Updated by malcolm harvey about 3 years ago

update: (Nothing writes to application but as brian points out above still that is wip).

Actions #10

Updated by malcolm harvey almost 3 years ago

Tested writing again, still in Rel 1.0 beta 11 wont write to actual file.

..

#splashScreen:false
Print "Current directory:";dir$       //Application direction for files read/write
print ""
dim mapposloc$(10)                    //(mapposloc) access file can be 10 positions (numbers)


     nextword$=""

                                      //Read.....from a file mapposloc.txt to array mapposloc$().

    Open in 1,"mapposloc.txt"         // Open the (mapposloc) access file

                                       // Sequential file handling

    For n = 1 to 10                    //mapposloc.txt has 10 items
        Input #1,nextword$             // Input from file or read to program memory each item in sequence from file number 1 into nextword, (#1)
        mapposloc$(n) = nextword$      //Place in element n of the array, mapposloc$(n) 1-10
        print nextword$                //print them to see on screen
        wait key
    Next

        print "first bit done, reading in 10 words"

        print ""
        print ""

    Close 1                            // Close the word list file

    print mapposloc$(1)                //now print the words out from array
    wait key
    print mapposloc$(2)                //what we read in
    wait key
    print mapposloc$(3)
    wait key

    print "second bit done,print to screen what we read frist 3 words"

    wait key

    print ""
    print ""

                                    //Write....To a file. (Does not work at this time to disk)
                                    //Seams like it works but it auctualy does not write to the file.


                                    //2) Write from array mylist() to wordlist.txt  //(10 words)

Open out 1,"wordlist.txt"             //Open the file for writing too

// Sequential file handling

For n = 1 to 10                   //Word list has 10 items
nextword$=mapposloc$(n)           //Element n or number from the array, mylist$
Print #1,nextword$                //Write to wordlist.txt or overwrite the old one if exists
Print nextword$                   //Print on screen nextword writing to file
  wait key
Next

    print "third bit done,write 10 files to file"

Close 1                               //Close the word file



end

Actions

Also available in: Atom PDF