We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Trying to save and load an array of integers
Page Index Toggle Pages: 1
Trying to save and load an array of integers (Read 292 times)
Trying to save and load an array of integers
Nov 13th, 2008, 8:54am
 
Hi there, I just recently started programming in Processing, and I'm have a hard time figuring out how to save and load a file from and integer array.  Specifically, I can save the file fine using createWriter(), but when I attempt to read it in using createReader() and the handle code I found in the example on this site, I end up with an empty array.  I've also tried using loadStrings() and saveStrings(), but it seems that processing won't let you specify a folder to read from or save to, and loadstrings saves to the main code folder while readStrings wants the file in the data folder.  I'm totally confused, can anyone help?
Re: Trying to save and load an array of integers
Reply #1 - Nov 13th, 2008, 3:53pm
 
AFAIK, you can specify an absolute path in most Processing functions operating by default on the data folder.

If you could provide the code you have tried so far, we could try and point out what is wrong, or at least test it ourselves.

Indicating which platform you use might be relevant too, for this kind of problem.
Re: Trying to save and load an array of integers
Reply #2 - Nov 13th, 2008, 8:36pm
 
I think I've solved the problem.  Not sure why it wasn't working the same way for me today as before - although I did just download the newest Processing build.  I'm at work but I had a few minutes so I tried this code out and it seems to work.

You asked what platform I'm running, I'm using Windows XP although I coded this on a vista machine.


void setup()
{
 //nothing here yet
}

void draw()
{
 int[] Arr = new int[49];
 String saveMe[] = new String[49];
 String loadMe[];
 
 for (int i = 0; i < 49; i++)
 {
   Arr[i] = i;
 }
 for (int i = 0; i < 49; i++)
 {
   saveMe[i] = str(Arr[i]);
 }
 
 saveStrings("save.ddd", saveMe);
 
 loadMe = loadStrings("save.ddd");
 
 println(loadMe);
 
}

 
Page Index Toggle Pages: 1