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 › Defining an enum.  What's the trick
Page Index Toggle Pages: 1
Defining an enum.  What's the trick? (Read 665 times)
Defining an enum.  What's the trick?
Feb 2nd, 2009, 8:53pm
 
I'm trying to create an enumeration to define node types for a tree structure I'm creating.  Only, processing doesn't like it.  If I define it after draw(), I get this:

processing.app.debug.RunnerException: unexpected token: Node

and the code editor hilights the line:

public enum NodeType {

If I move the definition to the front of the file, it gives me a different message:

processing.app.debug.RunnerException: expecting "class", found 'enum'

So yes, I'm a newbie, but I've read all the docs (which, by the way, don't mention enum) as well as the java language reference, so as far as I can tell I'm defining the enum correctly.  What's the trick?
Re: Defining an enum.  What's the trick?
Reply #1 - Feb 2nd, 2009, 9:21pm
 
whilst java supports enums since 1.5 and processing uses java 1.5 (or later) unfortunately the parser that the processing development environment uses doesn't understand them.
Re: Defining an enum.  What's the trick?
Reply #2 - Feb 3rd, 2009, 12:47am
 
As said by koogs, Processing uses Java 1.6 but has a pre-processor whose grammar is still at 1.4, so new constructs are not usable in .pde files.
Now, as somebody pointed out smartly, you can put such special definitions in a .java file in the sketch.
Re: Defining an enum.  What's the trick?
Reply #3 - Feb 3rd, 2009, 1:25am
 
Ok.  Well, I guess I feel better knowing that it wasn't me screwing up something really dumb.

I'll probably just define some constants instead.  Simpler.

Thanks for the info!
Page Index Toggle Pages: 1