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 › silly  string array question
Page Index Toggle Pages: 1
silly  string array question (Read 2655 times)
silly  string array question
Aug 25th, 2007, 1:57pm
 
Hi, this is my first post and already a pretty silly question I guess, but I can't figure out why it is like it is:

So, this works outside of void setup()

Code:

String[] toggleDimensionText = {"Mode: 3D","Mode: 2D"};


but this doesn't:
Code:

//outside of void setup()
String[] toggleDimensionText = new String[2];
// only works if inside of void setup()
toggleDimensionText[0] = "Mode 3D";
toggleDimensionText[1] = "Mode 2D";


The last example only works if I put the last two lines inside of void setup() and I can't figure out why???

The error message is 'unexpected token: void'

I thank you for any help and many thanks also to the developers for having created Processing!
Re: silly  string array question
Reply #1 - Aug 26th, 2007, 1:58am
 
it's just the semantics of the language. a simple way of putting it is that the code outside setup() is not read sequentially, so that type of syntax is disallowed (it's something we inherit from java). so basically, because there's no guarantee that "new String[2]" will run before "toggleDimension[0] = ...". because of the messiness of how such code would compile, it's just not allowed.
Re: silly  string array question
Reply #2 - Aug 26th, 2007, 12:35pm
 
ah! coming from a more procedural language I wasn't aware of this non-sequential behavior. In a pure Java environment, where would these commands outside of setup or any other function stand?
Re: silly  string array question
Reply #3 - Aug 26th, 2007, 9:48pm
 
this is behavior inherited from java, so it's identical to what you'd get there.
Page Index Toggle Pages: 1