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 › formatting text via a class
Page Index Toggle Pages: 1
formatting text via a class (Read 366 times)
formatting text via a class
Aug 20th, 2009, 2:36pm
 
Hi, I have a class that aligns text to the right margin. I'd like to pass a string to it and have it return the formatted string. Then, in the main part of the program, I'd use the text() function to draw to the screen.

I never really understood how to get information back from a class. Do I include return in there somewhere? How do I access this returned information in the main program?
Re: formatting text via a class
Reply #1 - Aug 20th, 2009, 2:39pm
 
Classes don't return values. Methods do.

Code:
class Foo {
 void a() {
   // this method doesn't return anything (void)
 }
 int b() {
   // this method returns an integer (int)
   return 12;
 }
}


Just call the method on your object :

Code:
Foo myObject;
println(myObject.b());
Page Index Toggle Pages: 1