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.
Page Index Toggle Pages: 1
passing data (Read 1052 times)
passing data
Feb 6th, 2010, 7:00pm
 
Hello,
I'm new at this, and I don't understand a lot, so if this has been discussed else where, please forgive me, I am very confused.

I am trying to pass data from one array into another? Is that the way you say it?

I am reading values from a text file, then trying to give that output to another array for display. Here is a code snippet, does anyone know what's going on and how I should be looking at this?

In the draw loop I have:

if (index < lines.length) {
   String[] pieces = split(lines[index], '\t');
   if (pieces.length == 2) {
     int x = int(pieces[0]) * 2;
     int y = int(pieces[1]) * 2;
     int da = x-y;
     println(da); //this is the info i want to pass down
    // return da;
     }
     // Go to the next line for the next run through draw()
     index = index + 1;
 }

In the setUp loop there is:
 for (int i=0; i < springs.length; i++){
   springs[i] = new Spring(nodeA, nodes[i]);
  springs[i] .setLength(100);
  springs[i] .setStiffness(da);
  springs[i] .setDamping(0.3);
  }

but even if I move this to the draw loop, it does not change anything.
Sorry if this is a bother, and thank you for your attention.
Re: passing data
Reply #1 - Feb 7th, 2010, 1:18am
 
whats the problem when using the code in the draw loop?

like you maybe realized you are using "da" in setup before it is even initialized in draw. i am not sure what you want to do but maybe you need to move the if(index stuff into its own for loop in setup above the spring creation
Re: passing data
Reply #2 - Feb 9th, 2010, 3:45am
 
I'm not sure where exactly your code is placed, but variables defined within a function(including setup and draw) are not accessible outside that function.  It appears as if you have defined da within draw and are trying to access it in the separate function setup and before it is defined.  Try defining the variable at the top of the sketch before setup.  if that doesn't work try passing da to the springs array as the srtings are parsed:

Code:

if (index < lines.length) {
  String[] pieces = split(lines[index], '\t');
  if (pieces.length == 2) {
    int x = int(pieces[0]) * 2;
    int y = int(pieces[1]) * 2;
    int da = x-y;
    println(da); //this is the info i want to pass down
   
   springs[index] .setLength(100);
   springs[index] .setStiffness(da);
   springs[index] .setDamping(0.3);
   

    }
    // Go to the next line for the next run through draw()
    index = index + 1;
}


hope that helped
Page Index Toggle Pages: 1