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 › Constructor Problem, help please.
Page Index Toggle Pages: 1
Constructor Problem, help please. (Read 447 times)
Constructor Problem, help please.
Nov 13th, 2007, 7:50pm
 
I'm new to processing and I'd like to make a constructor and later an array made of constructors. I did check the help and I've found quite a number of examples of constructors, but when I apply the same code to my sketch it doesn't work. Please help!

this is the code in my sketch, atm at least.

PFont fontA;
fontA = loadFont("CordiaUPC-48.vlw");
textFont(fontA);

String[] lines;
weatherData table[] = new weatherData[548];

int numLines = 0;
lines = loadStrings("Greenwich.txt");
numLines = lines.length;

size(500,500);
String txt=String.valueOf(numLines);

String s;
String s1;
String s2;
String s3;
String s4;
String s5;
String s6;
String s7;


//for(int i = 20; i<569; i++)
//{
s1 = trim(lines[20].substring(3,7));
s2 = trim(lines[20].substring(9,11));
s3 = trim(lines[20].substring(14,18));
s4 = trim(lines[20].substring(22,26));
s5 = trim(lines[20].substring(32,34));
s6 = trim(lines[20].substring(37,42));
s7 = trim(lines[20].substring(45,50));

if(s6.equals("---"))
{
 s6 = "0";
}

if(s4.charAt(0) == '-')
{
 s = s4.substring(1);
}



//}

text(s1, 0, 30);

class weatherData
{
 int yearw;
 int monthw;
 float tmax;
 float tmin;
 int af;
 int rainmm;
 float sunHours;

 weatherData(int y, int m, float tx, float tn, int a, int r, float s)
 {
   yearw = y;
   monthw = m;
   tmax =tx;
   tmin =tn;
   af = a;
   rainmm = r;
   sunHours = s;
 }
}

Don't mind the other part of the code, just the constructor part and the array made of constructors.

Anyway, I get the error message:
Semantic Error: Type "weatherData" was not found.

Please help!
Re: Constructor Problem, help please.
Reply #1 - Nov 13th, 2007, 8:19pm
 
If you want to use classes, you've got to use the setup()/draw() style of code I believe.
Re: Constructor Problem, help please.
Reply #2 - Nov 13th, 2007, 10:28pm
 
Tnx for help, gonna try that now.
Page Index Toggle Pages: 1