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)
   beginner; writing functions
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: beginner; writing functions  (Read 382 times)
pinksalmon


beginner; writing functions
« on: Jan 28th, 2003, 6:43pm »

I've just started proce55ing today...
I'm playing around to get the know the way of scripting and I keep on having troubles with writing functions (or methods as they're called if I'm not mistaken);  
"unexpected token" is the error message I get all the time. here is an example:
 
int GLOBVAR1 = 1;  
 
int addertron(int g) {  
  return g += 2;  
}  
 
GLOBVAR1 = addertron(GLOBVAR1);  
println(GLOBVAR1);
 
"unexpected token: int"
 
REAS


WWW
Re: beginner; writing functions
« Reply #1 on: Jan 28th, 2003, 9:22pm »

To write your own functions, you need to write your code using the setup() and loop() structures. Setup() is called once when the program begins and loop() is read continually until the program stops.
 
Code:

int GLOBVAR1 = 1;
   
void setup()
{
  size(200, 200);
}
 
void loop()  
{
  GLOBVAR1 = addertron(GLOBVAR1);  
  println(GLOBVAR1);  
}
 
int addertron(int g) {  
  return g += 2;  
}  
 
Pages: 1 

« Previous topic | Next topic »