How do I store an array in a text file and then retrieve it again?
Revolution enables you to convert an array into a format that can be stored in a file or sent to a URL using arrayEncode. Conversely, you can use arrayDecode to to convert data back into a Revolution array.
This lesson will show you an example of how to use arrayEncode/arrayDecode with the fillGradient property of a graphic.
The Example Stack
Storing an Array in a File
This code snippet from the example stack demonstrates how to convert the fillGradient property (an array) of a graphic into a binary representation of the array using arrayEncode. This binary representation is stored in the variable theEncodedArray.
When storing the array in a file it is important that you write the data to the file in binary format otherwise the encoded array data will be corrupted. That is why the binfile: prefix is used.
Loading an Array From a File
To load the binary representation of the array from a file you just reverse the steps. Begin by reading the data from the file in binary format using the binfile: prefix. In this snippet the binary data is stored in the variable theEncodedArray.
You can then pass the binary data to arrayDecode which transforms the binary data back into a Revolution array variable, theFillGradientA in this case. At this point the array can be assigned to the fillgradient property of a graphic.