[18 Dec 2006] file-handler

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
GMKai
Posts: 158
Joined: Mon Feb 15, 2010 10:58 am

[18 Dec 2006] file-handler

Post by GMKai »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 18 Dec 2006 14:26:29 +0100

Hello, I am trying to write from a table to an existing file. But "OpenFile" fails to open the existing file. Here is what I try to do:

Code: Select all

Function p_ScoreOpener(mode)
    Local f_exists
    Switch scoreclass
     Case 0:
          f_exists = Exists("scr/attack0.scr")
          if f_exists = TRUE
              OpenFile(1,"scr/attack0.scr",mode)
          endif
     Case 1:
          f_exists = Exists("scr/attack1.scr")
          if f_exists = TRUE
              OpenFile(1,"scr/attack1.scr",mode)
          endif
     Case 2:
          f_exists = Exists("scr/attack2.scr")
          if f_exists = TRUE
              OpenFile(1,"scr/attack2.scr",mode)
          endif
    EndSwitch
    return (f_exists)
EndFunction

Function p_FillScoreTab()
    if p_ScoreOpener(#MODE_READ) = TRUE
         Seek(1,0)
         Local i = 0
         While NOT EOF(1)
            scoretab[i][0] = ReadLine(1)
            scoretab[i][1] = ReadLine(1)
            i = add(i,1)
         Wend
         CloseFile(1)
    endif
EndFunction

Function p_SaveScores()
    if p_ScoreOpener(#MODE_READWRITE) = TRUE
         Seek(1,0)
         for i = 0 To 9
               if scoretab[i][0] <> ""
                  WriteLine(1,scoretab[i][0])
                  WriteLine(1,scoretab[i][1])
               endif
         Next
         CloseFile(1)
    endif()
EndFunction

Function p_CheckScores()
    changed = 0
    scoreclass = difficulty
    p_FillScoreTab()
    Local count = 9
    for i = 0 To count
        if scoretab[i][0] = NULL
           p_UpdateEntry()
           Break()
        elseif Score > scoretab[i][1]
           for k = count-1 to i Step -1
                 scoretab[k][0] = scoretab[k-1][0]
                 scoretab[k][1] = scoretab[k-1][1]
           Next
           p_UpdateEntry()
           Break()
        endif
    Next
    If changed = 1
       p_SaveScores()
    endif
EndFunction
When reading from file to the table, everything is fine. But when trying to write from table to file, it fails because the file can't be opened. Do I have to delete the file previously and then open it for writing where it should be created? What else could make the filehandler fail?
SamuraiCrow
Posts: 475
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

[18 Dec 2006] Re: file-handler

Post by SamuraiCrow »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 18 Dec 2006 16:43:05 -0000

Are you opening the file in append mode? You shouldn't be. Are you opening the file in "old" mode? This will not erase the old contents of the file. Opening the file in "new" mode should do the trick. (I'm operating from memory of DOS.library without looking at the Hollywood guide file upstairs on my AmigaOne.)
I'm on registered MorphOS using FlowStudio.
GMKai
Posts: 158
Joined: Mon Feb 15, 2010 10:58 am

[19 Dec 2006] Re: Re: file-handler

Post by GMKai »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Tue, 19 Dec 2006 07:58:32 +0100

The "mode" just says #WRITE or #READ_WRITE, this shouldn't change the file's content. but it just fails to open the file. I am planing to change the file afterwards. Now my attempt is to read the file into a table, delete the file and create it new from the table.
User avatar
airsoftsoftwair
Posts: 5832
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[22 Dec 2006] Re: Re: file-handler

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Fri, 22 Dec 2006 20:51:47 +0100
The "mode" just says #WRITE or #READ_WRITE, this shouldn't change the file's content. but it just fails to open the file. I am planing to change the file afterwards. Now my attempt is to read the file into a table, delete the file and create it new from the table.
Did you check the output from SnoopDOS? Maybe the file is read or write protected. Check the protection flags.
GMKai
Posts: 158
Joined: Mon Feb 15, 2010 10:58 am

[26 Dec 2006] Re: file-handler

Post by GMKai »

Note: This is an archived post that was originally sent to the Hollywood mailing list on 26 Dec 2006 14:01:48 +0100

Hallo Andreas,

within Snoopium there is no fail for the file when wanting to write to it. Flagwise the file is "rwed". As deleting and recreating the file works here, the problem is solved.
Locked