At 03:44 -0500 02/22/2002, Jason Je wrote:
>I have a simple FileIO and list question...
Before you go any farther, it sounds like you don't need FileIO at
all. You should be able to do everyhting using setPref and getPref,
which have the added value of being Shockwave safe, so you can use it
in a browser setting, unlike FileIO.
To write your data:
setPref ( "Filename", data )
To read it:
data = getPref ( "Filename" )
Where data is, of course, the string to read/write -- as an entire
variable -- and "Filename" is the name of the file you want saved
(user name, etc).
setPref writes a plain text file to a folder called "Prefs" which, if
not present, is created alongside your projector when the call is
made. It reads the data from the same location.
If you do a getPref on a text file which does not exist, your
variable will be void, so you can determine whether it's even there
to begin with. Here's a simple script you can call fromk your message
window. (Prefs in author are written alongside the Director program,
not the .dir file).
on TestPrefs
data = getPref ( "Filename" )
if voidP ( data ) then
put "Creating file"
setPref ( "Filename", "This is a prefs file." )
Testprefs()
else
put data
end if
END TestPrefs
Now to your particular questions, even if they've been rendered
academic by the presence of setPref/getPref. ;)
>I made a board game in flash that reads stage data from
>the text file... This text file, SymbolsData.txt is formatted
>like this...
>
>(Made several lines for your eyes... It really is a one liner...)
>TotalSymbols=4&
>Symbols=12!21!23!30!34!40!42!44!51!53
>~11!13!22!30!31!33!34!41!43!51!53!62
>~12!21!23!30!34!40!44!51!52!53
>~30!40!21!51!12!42!23!53!34!44
I assume this is an actual text string, not some kind of weird Flash
variable. That is, this has "" around it, correct? FileIO requires
text to be written.
That's not a problem, of course. For instance if you have a list:
list = [#first:"Hello", #second:"World"]
you can convert it to a string before you write it. With either
FileIO or setPref, it's this simple:
data = string ( list )
Then your data is OK to write as a string.
When you want to convert it back into a "real" list form (after
you've read it in), you pass it through the value filter:
list = value ( data )
Then it's a list again and everything's dunky hory.
>Then, I want to create a little program that does...
>1. reads the same data file in Director on the start of the movie
Well, you know how to do that rather painlessly now. ;)
>2. parse the data into the form of the list,
If you write it out using the string and retrieve it using the value
filters, you might be OK there too.
>3. display the data in graphical format(simple on and off of
> 5 X 10 matrix)
That's your deal. You can do it however you want.
>4. user can have options to navigate the list or add or delete
> the record,
Same.
>5. put the list back into the above format and save the text file.
Same again. ;)
>I need to omit the displayOpen command on that sample because
>I already know what file to open and save... So, I thought that
>I could just specify the file name to open... bang!!! What???
>'Bad file name' error??? what bad file??? I just don't get it...
>What did I do wrong??? I just told you the name of the file to open!!!
OK, I've got links to FileIO docs in my book support section at
nightwares. I'd recommend you go over those thoroughly. It's entirely
possible to get FileIO to open or close files without using the
open/save dlogs.
I've even got a section under faq --> lingo on FileIO.
>And... when I opened the text file with the open dialog box and
>put the content of the file into the message window, I get
>"whatever_the_content_of_the_file"... Why am I getting the double
>quotes??? Anyway to get rid of it???
Again, because FIO uses strings. You cna, as described, pass it
through value to change that.
>One more question... I didn't go that far yet, but I gotta ask...
>How does FileIO read a data from the file??? Byte at a time, line
>at a time, or whole data at a time???
Any of several ways. You can do readLine, readChar or readFile.
Just structure your data as you want it to be used, convert it to a
string, setPref to save it, getPref to read it back, pass the string
through value, and go thy way with joy. :D
--
Warren Ockrassa | http://www.nightwares.com/
Director help | Free files | Sample chapters | Freelance | Consulting
Author | Director 8.5 Shockwave Studio: A Beginner's Guide
Published by Osborne/McGraw-Hill
http://www.osborne.com/indexes/beginners_guides.shtml
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list, email
[EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for
learning and helping with programming Lingo. Thanks!]