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 › cant define properly functions in mac osx
Page Index Toggle Pages: 1
cant define properly functions in mac osx (Read 629 times)
cant define properly functions in mac osx
May 6th, 2008, 4:02am
 
I'm new at this, but I typed the following code:

int fact(in n) {
if ( n <= 1 ) { return 1; } else { return n*fact(n-1); }
}

That I think it's ok. But the compiler says: "unespected token int" (the first "int"). If I put before:

void draw() {
int f = factorial(3);
print(f);
}

Then the error dissapears, but then I can't define any other functions.

Please tell me the correct form to do this.
Re: cant define properly functions in mac osx
Reply #1 - May 6th, 2008, 5:41am
 
this works for me on osx 10.4.11

Code:


void draw() {
int f = fact(3);
print(f);
}

int fact(int n) {
if ( n <= 1 ) { return 1; } else { return n*fact(n-1); }
}


Re: cant define properly functions in mac osx
Reply #2 - May 28th, 2008, 10:03am
 
If you've typed some custom functions, then you've got to add at least one of the main methods if you want your code to compile correctly, either setup(), or draw(), or both (even if they are empty).

Code:
void setup() {}
void draw() {}

int myFunction(int i) {
...
}


See Reference > Environment > Programming modes for more info :
http://processing.org/reference/environment/index.html#Programming_modes

Quote:
This mode provides a setup() structure that is run once when the program begins and a draw() structure which by default continually loops through the code inside. This additional structure allows writing custom functions and classes and using keyboard and mouse events.


Page Index Toggle Pages: 1