Shockwave is designed so that you cannot do anything harmful to a user's hard-drive. As a result, the only way to save data to disk and load it back in is to use the specific commands setPref and getPref functions as follows:
tPrefName can be any standard file name (although it is better to stick to 8 characters for early versions of Windows), but the extension (if not supplied, it defaults to .TXT) can only be .TXT or .HTM.
tPrefValue can only be a string. However, virtually anything in Director can be converted to a string by using the string() function. From a single variable, to a property list, an entire field-full of text or even HTML code, anything can be stored this way
The value returned from getPref will likewise always be a string. However, since you know what you saved, it is easy to convert.
For example I wish to save the value contained in gHiScore using the file 'hiscore.txt' then I would do:
setPref "hiscore.txt", string(gHiScore)
and to load it in:
gHiScore = value(getPref("hiscore.txt"))
Note how I converted gHiScore to a string before saving and converted back to a value when I loaded it in. This is important to note if you are attempting to save and load floating point values. When you convert a floating point value into a string, it is converted to use the number of decimal places used in the floatPrecision movie variable. To maintain maximum accuracy set this before you convert:
the floatPrecision = 15
If this code is part of a general routine, or you are setting the floatPrecision elsewhere in your movie, it is good practice to store the old value of the floatPrecision and revert back to it after you have finished:
tOldPrecision = the floatPrecision
the floatPrecision = 15
setPref "float.txt", string(tFloat)
the floatPrecision = tOldPrecision
Saving / loading multiple items:
If you wish to save more than one item of data, then rather than use multiple files you could, for example, place all the values in a list and save that:
For the extra complicated, it is entirely possible to create the HTML page saving data the user cannot see, by embedding the data in the middle of a comment tag before saving the whole lot in one go. This is easiest if you use a field (in this example called "HTML to save") to hold the contents of what you want to save first. Assuming you have another field (in this example called "Empty HTML") which contains:
Demo saving data into a comment tag
This is the text you see when you view this as a web page.
Note that the line is the first line of the field. This means that the empty comment line is line 8 of the field.
So to save a variable called tName to a file called "Name.htm" in the hidden comment line you’d do:
member("HTML to save").text = member("Empty HTML").text
member("HTML to save").line = tName
setPref "Name.htm", member("HTML to save").text
To get the value out you’d reverse the above sequence (this example uses another field "HTML to load" although you do not need two separate fields using these examples):
member("HTML to load").text = getPref("Name.htm")
tName = member("HTML to load").line
In all cases when using getPref() it is usually safer to check the results from it. If the loading was unsuccessful, then getPref() returns VOID. For the sake of clarity I have omitted this step in my code examples above. One simple technique would be to attempt to load the pref file at the start, and if it returns VOID then create a default one immediately.
36 South Court Sq
Newnan, GA 30263