7 Replies Latest reply on Aug 8, 2008 5:09 PM by Newsgroup_User

    Capturing fileio script errors

    65Cobra
      Howdy, I need a little help getting these pesky "script errors" to keep from popping up.

      I am using fileio to save preferences. Everything works fine unless there is a permission problem. In this case, Director just pops up a "script error".

      Instead of that message popping up on error, I would like to replace with with my own message, something like "cannot write file, permission denied". Simple enough but I'm not sure what lingo I use to trap the error and keep it from popping up with the script error. My lingo is...


      io = new Xtra("fileio")
      path = the pathname & "ndata.txt"
      io.openFile(path,0)
      io.delete()
      io.createFile(path)
      io.openFile(path,0)
      gameprefs = pName & "," & AA & "," &O_Buffer
      io.writeString(string(gameprefs))
      --io.writeString(string(pName))
      io.closeFile()

      Any help would be appreciated! Thank you!
        • 1. Re: Capturing fileio script errors
          Level 7
          It's not clear which line of code is throwing an error, and it would
          help if you included details of the error message in the future.

          Try the following, and see which line is the last in your message window
          when the error dialog presents:
          --
          put "instancing xtra"
          io = new Xtra("fileio")

          path = the pathname & "ndata.txt"
          put "openFile"
          io.openFile(path,0)

          put "delete"
          io.delete()

          put "createFile"
          io.createFile(path)

          put "openFile: 2"
          io.openFile(path,0)

          gameprefs = pName & "," & AA & "," &O_Buffer
          put "writeString"
          io.writeString(string(gameprefs))
          --io.writeString(string(pName))

          put "closeFile"
          io.closeFile()
          --

          I would also suggest you add some error trapping - or at least
          monitoring - of calls to FileIO by using its 'status()' method:
          --
          put "instancing xtra"
          io = new Xtra("fileio")

          path = the pathname & "ndata.txt"
          put "openFile"
          io.openFile(path,0)
          put io.status(), io.error()

          put "delete"
          io.delete()
          put io.status(), io.error()

          put "createFile"
          io.createFile(path)
          put io.status(), io.error()

          put "openFile: 2"
          io.openFile(path,0)
          put io.status(), io.error()

          gameprefs = pName & "," & AA & "," &O_Buffer
          put "writeString"
          io.writeString(string(gameprefs))
          put io.status(), io.error()
          --io.writeString(string(pName))

          put "closeFile"
          io.closeFile()
          put io.status(), io.error()
          --
          • 2. Re: Capturing fileio script errors
            pete.h Level 1
            You could also check out "alerthook", in Director help.
            • 3. Re: Capturing fileio script errors
              65Cobra Level 1
              Thanks guys. I believe it's the createFile() that is giving the error since in Vista, I didn't have the permission to do so. I'll give these ideas a shot.

              Sean, do you have a paypal account?
              • 4. Re: Capturing fileio script errors
                Level 7
                > Thanks guys. I believe it's the createFile() that is giving the error since in Vista, I didn't have the permission to do so. I'll give these ideas a shot.

                On Vista, in particular, you need to be careful that files you write to
                are in write-enabled directories. Buddy API's 'baSysFolder("personal")'
                is useful for determining this

                > Sean, do you have a paypal account?

                Yes, but I'm not sure what you're driving at. None of us expect payment
                for help provided here
                • 5. Re: Capturing fileio script errors
                  65Cobra Level 1
                  Thanks again Sean. I appreciate the time it takes to provide answers and just want to give a little back that's all.

                  The script error was popping up in Vista if I just copied the files over from my XP system (where everything is authored) and ran it like that. If I actually created an installer for the program and install, then run the software, then it works fine, writing the preference file without any errors. I just wanted a backup plan in case a user had any write/permission issues that it would give a message like "cannot write file, check permissions and disk space" rather than the ugly Director script error window.
                  • 6. Re: Capturing fileio script errors
                    65Cobra Level 1
                    Ok status() works great.

                    One other area that can cause the script area is where I record a sound file, then save it. Again, if the permissions aren't there, the game will provide a script error. Unfortunately, the line of code to save the file is the one that causes the error so I'm not sure how to write the line while checking for errors before it actually causes them. Hope that makes sense.

                    The line that causes the problem I believe is the "saveasfile" command.

                    set theXtra to new (xtra "RecSndXtra")
                    (opens file and starts recording, this part works)


                    theXtra.SaveAsFile(path)
                    theXtra.CloseAudio()

                    Is there a way to write the lingo so that it attempts to save the file but returns an error instead of displaying "Script error"?

                    I suppose the other alternative is to test the write permission of the dir and if it's no-write, then I don't even attempt to "saveasfile".

                    Thoughts?

                    Help is MUCH appreciated.
                    • 7. Re: Capturing fileio script errors
                      Level 7
                      > I suppose the other alternative is to test the write permission of the dir and
                      > if it's no-write, then I don't even attempt to "saveasfile".

                      Bingo, or alter the path you're saving to