9 Replies Latest reply on Apr 18, 2008 6:31 PM by Newsgroup_User

    File IO

    WarDemonZ Level 1
      Hey everyone, iv really been having trouble working with File IO, im 99% complete on my project, everything works but it doesnt save to file like i need it to, iv got a test file off deansdirectortutorials.com or something like that, which just has a simple interface allowing u to write to, append, and open a file that gets saved. iv literally copied the code word for word from his (made changes where appropriate) and mine just doesnt work. does anyone know a nice simple method of doing them, i really need to learn how to do it asap. any help you guys could give would be fantastic.

      also a little less important thing, when entering info in from the code, i want to change the text of a sprite, so i put in sprite(x).member.text = " etc etc, is there a way of doing a 'return' in the code, as in, like hitting the enter key so it puts the remainder of the text on a new line?

      thanks everyone
        • 1. Re: File IO
          Level 7
          What is on Dean's tutorial is about as simple as it gets. If you used
          that to work with, then you are probably very close to making it work.
          Can you post your code or give a clue as to where it is failing?

          To insert a return in a text member:

          sprite(x).member.text = "This is line 1" & RETURN & "This is line 2"

          RETURN is a key word that represents a new line character and the
          ambersand (&) is the string concatentor.


          WarDemonZ wrote:
          > Hey everyone, iv really been having trouble working with File IO, im 99%
          > complete on my project, everything works but it doesnt save to file like i need
          > it to, iv got a test file off deansdirectortutorials.com or something like
          > that, which just has a simple interface allowing u to write to, append, and
          > open a file that gets saved. iv literally copied the code word for word from
          > his (made changes where appropriate) and mine just doesnt work. does anyone
          > know a nice simple method of doing them, i really need to learn how to do it
          > asap. any help you guys could give would be fantastic.
          >
          > also a little less important thing, when entering info in from the code, i
          > want to change the text of a sprite, so i put in sprite(x).member.text = " etc
          > etc, is there a way of doing a 'return' in the code, as in, like hitting the
          > enter key so it puts the remainder of the text on a new line?
          >
          > thanks everyone
          >
          • 2. Re: File IO
            Level 7
            Summarizing Dean's tutorial, to create a file and save text to it you
            need to issue the following commands:

            scribe = new (xtra "FileIO")
            createFile (scribe, the moviePath&"Multimedia.txt")
            openFile (scribe, the moviePath&"Multimedia.txt", 0)
            writeString (scribe, "Exporting text in Director is easy!")
            closeFile(scribe)
            scribe=0

            Line 1 creates an instance of the FileIO xtra and assigns a reference to
            it to the variable named scribe

            Line 2 using the instance created in Line 1 to create a file named
            "Multimedia.txt" which is created in the same folder that the movie is
            saved in.

            Line 3 opens the file for writing

            Line 4 writes text to the open file

            Line 5 closes the file

            Line 6 disposes on the instance created in Line 1
            • 3. Re: File IO
              rafa@mediatech Level 1
              Hey WarDemonZ:
              I am not the greatest in Director, but I ran into a similar problem in a project a few moths ago, it turned out that I forgot to set my "movie script" code. I just wanted to throw that in there...maybe thats what you are missing.

              global myFile
              on startMovie()
              myFile = new(xtra "fileio")
              end
              on stopMovie
              myFile = 0 -- Dispose of the instance
              end

              Hope it works!
              • 4. Re: File IO
                WarDemonZ Level 1
                hey guys, im still having ridiculous troubles with it, i just cant get it to work for the life of my, iv followed the deans tutorial thing down to a tee, but everytime i try to read from the file i just get <void>

                it does the same when i copied wot u guys have written and when i try to copy the code from the pre built file on the website, any suggestions?
                • 5. Re: File IO
                  WarDemonZ Level 1
                  iv just had another thought, the data that im going to be saving to the file is a set of lists, as this is the way im planning on making the program and its pretty vital that it still saves the lists correctly

                  basically if u can imagine iv got

                  namelist [john, dave, simon]
                  surnamelist [thomas, peters, morris]
                  height [175,180,190]
                  etc

                  how will it actually save it, cos iv just looked at the file it makes and thats just a static text file, but if the lists have to repopulate themselves from the text then that will return them all as strings wont it? some of them have to be numbers in order for some of my program to work.
                  • 6. Re: File IO
                    Level 7
                    The only reason I can imagine that it isn't working is if you are
                    running it from a new movie that you have not yet saved. If that is the
                    case then "the moviePath" will be null, and trying to write or read a
                    file without a fully qualified path will fail.

                    Where exactly does it fail? Line 1? Line 2?
                    • 7. Re: File IO
                      Level 7
                      Yes, saving a list with fileIO converts it to a string. There is a free
                      Xtra that will allow you to save lists (and other data types) without
                      converting to strings.

                      http://www.pimz.com/?id=xtras&section=propsave

                      • 8. Re: File IO
                        Level 7
                        By the way, I don't believe propSave Xtra has been updated for D11.


                        Dave C wrote:
                        > Yes, saving a list with fileIO converts it to a string. There is a free
                        > Xtra that will allow you to save lists (and other data types) without
                        > converting to strings.
                        >
                        > http://www.pimz.com/?id=xtras&section=propsave
                        >
                        • 9. Re: File IO
                          WarDemonZ Level 1
                          its fine, iv got it, wooooo im really happy to have that working, i needed to make a txt file for each list but it works, so im happy, cheers guys