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 › some functions (like int) not working
Page Index Toggle Pages: 1
some functions (like int) not working (Read 503 times)
some functions (like int) not working
Sep 10th, 2006, 10:52pm
 
Hi
this is my first time posting, and I'm brand new to Processing.

I'm trying to make a simple sketch and for some reason, the program won't recognize the "int" command.  It says "unexpected token: int"
Any advice?

Thanks
Re: some functions (like int) not working
Reply #1 - Sep 10th, 2006, 11:27pm
 
You should post some code.  Too hard to tell what might be wrong if we cant see the actual code.

When posting code, be sure to use the [ code] and  [ /code] tags so it formats properly.  (remove the space from before 'code' and '/code')
Re: some functions (like int) not working
Reply #2 - Sep 11th, 2006, 2:40pm
 
Not that I'm an expert in Processing, but with the lil bit of experience I've got, this is what I think would've gone wrong...
You've most probably put the int, between the setup() and the draw() function.
Processing allows global variables to be declared before the setup() function, but if you want to declare variables anywhere else, you'll have to declare variables, inside functions.
or, you might have missed out a semicolon or a closing bracket somewhere. Smiley Posting the code will get you help a lot more faster. Smiley
Cheers
Re: some functions (like int) not working
Reply #3 - Sep 12th, 2006, 12:00am
 
I'm sure what your happen, normal is better put the code in the post to help you.

This piece of code make a some variable int, one of the are empty(with put his name of variable) and proboke an error: "unexpected token: int".

Code:

int var_a1=2;//ok
void setup(){}
int var_a2=66;//ok
void draw(){}
int ;// -> this proboke an error: "unexpected token: int"
//between "int" and ";" needs the name of variable
// the only rule of name of variables is that need start with a letter no a number and not use special characters like %, #, or /


mar
Re: some functions (like int) not working
Reply #4 - Sep 12th, 2006, 12:44am
 
"int ;" means nothing. int isn't a function, it's a keyword that tells procerssing what type a variable is. Without the name of a variable, it's meaningless, and so produces that error.
Re: some functions (like int) not working
Reply #5 - Sep 12th, 2006, 6:12am
 
True, besides, the title of this post is 'some functions like int not working'. I guess we're not dealing only with the int problem. Lets see what minim has to say about the problems he's facing.
Re: some functions (like int) not working
Reply #6 - Sep 12th, 2006, 11:32am
 
Sorry my English I not native and so perfect. But The Only that i would show is some examples of that error in different cases.
I show three examples of int working and proboke the error:"unexpected token: int".

1)
http://dev.processing.org/bugs/show_bug.cgi?id=212
Code:
int color = 0xFF; 



2)
http://dev.processing.org/bugs/show_bug.cgi?id=4
Code:
int u = (int(x)/width); 



3)
http://processing.org/discourse/yabb/YaBB.cgi?board=Syntax&action=display&num=1043775806

This code proke also a "unexpected token: int"
Code:
int GLOBVAR1 = 1;  
int addertron(int g) {
return g += 2;
}
GLOBVAR1 = addertron(GLOBVAR1);
println(GLOBVAR1);

this the correctly code
Code:

int GLOBVAR1 = 1;
int addertron(int g) {
return g += 2;
}
void setup(){
GLOBVAR1 = addertron(GLOBVAR1);
println(GLOBVAR1);
}


mar
Re: some functions (like int) not working
Reply #7 - Sep 12th, 2006, 1:28pm
 
1) "color" is reserved by by Processing as a function and datatype. Note that the following code works:
Code:

int x = 0xFF;

That's why color appears shaded red. Solution: don't use reserved names - even as local variables they can bite you in the ass.

2) Processing has a function called int() allowing you to cast variables into an int(). This is good for beginners but must be discarded as you advance in skill because Java can be a bit funny about what will parse and what won't. Instead use the following format:
Code:

// (castInto)variable
// eg:
int u = ((int)x/width);


3) Sometimes the bare minimum code you can run must have "void setup(){}" in it. Remember that Processing is putting a Java application together for you and has to guess at what you're doing, look after Processing and Processing will look after you.
Page Index Toggle Pages: 1