FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   adressing vars
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: adressing vars  (Read 808 times)
miasma


adressing vars
« on: Feb 13th, 2005, 9:15pm »

hi all.
 
this is really basic stuff i'm sure but i cant seem do adress variabes dynamicallly, like i used to do in acionscript. example:
 
background("maxvar_"+1,maxvar_2,maxvar_3);
 
or
 
background(int("maxvar_"+1),maxvar_2,maxvar_3);
 
or anything else i tried.
 
another example:
for (int c=0;c<num;c++) {
    y= "maxvar_"+c;
}
 
making an array is not really an option because the vars have to be declared publicly(maxlink) and if i put them in an array like "public float myarray[] = {maxvar_1,.....} it doesnt work.
 
so i'm sorry if this is really simple but i'm stuck.
 
thx a lot in advance.
 
miasma
 
JohnG

WWW
Re: adressing vars
« Reply #1 on: Feb 14th, 2005, 11:41am »

you can't create the name for a variable dynamically in Java, like you can in javascript and actionscript.
 
I'm not quite sure why you say an array wouldn't work.
 
Code:

//outside of setup, loop etc..
float[] myarray;
 
//in setup()
myarray=new float[3];
myarray[0]=maxvar_1;
myarray[1]=maxvar_2;
myarray[2]=maxvar_3;

that should create the array, and populate it,and have it available to all your code.
 
Then you'll be able to do:
Code:

background(myarray[0],myarray[1],myarray[2]);
 
//and
 
for(int i=0;i<myarray.length;i++)
{
  y=myarray[i];
}
 
Pages: 1 

« Previous topic | Next topic »