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 › dumb about programming mode
Page Index Toggle Pages: 1
dumb ? about programming mode (Read 545 times)
dumb ? about programming mode
Oct 8th, 2005, 11:26pm
 
I think my Processing program is set to 'Basic' programming mode, as opposed to Continuous or Java. It comes and goes, i.e. sometimes it works with 'Continuous' code pasted into it. However, universally it thinks that voids and curlies don't belong there when I'm working in a 'new' sketch.

Example- this program won't run:

int[] numbers = new int[4];
numbers[0] = 100;
numbers[1] = 100;
numbers[2] = 100;
numbers[3] = 100;

void setup(){
 size(400, 400);
 color(0,0,0);
 stroke (200);
}
void draw(){
 rect(numbers[0], numbers[1], numbers[2], numbers[3]);
}

-but this one will:

int[] numbers = new int[4];
numbers[0] = 100;
numbers[1] = 100;
numbers[2] = 100;
numbers[3] = 100;


 size(400, 400);
 color(0,0,0);
 stroke (200);

 rect(numbers[0], numbers[1], numbers[2], numbers[3]);

I cannot find anything on where/how this is controlled. Please help.
Re: dumb ? about programming mode
Reply #1 - Oct 9th, 2005, 1:14am
 
Code:

int [] numbers = new int[4];
void setup(){
size(400, 400);
numbers[0] = 100;
numbers[1] = 100;
numbers[2] = 100;
numbers[3] = 100;
stroke(200);
}
void draw(){
rect(numbers[0], numbers[1], numbers[2], numbers[3]);
}

  • Sometimes you have to set values in setup() instead of before it. Think of the preamble as getting out the different size containers you're going to need, and then in setup() you start putting stuff in to get it ready. Pretty much the same as how you set up classes and objects. Basic containers are all right to be pre-filled before setup() (int, float, String), but the more complex ones (arrays, objects) won't stand for it.
  • color() returns an int value. It is used to make the assignment of colours easier to understand when you start working with Processing. eg:
    Code:

    color col = color(255,255,0);
    fill(col);
    rect(0,0,50,50);
    print(col);

    To my knowledge it doesn't initialise anything in the sketch. So color(52,32,0); on its own would be meaningless.
Re: dumb ? about programming mode
Reply #2 - Oct 9th, 2005, 1:51am
 
st33d, thanks. 'Twas exactly right. And thanks for the illustrative metaphor, too. 'S helpful. Props also must be given to Zaphod, who phoned me with similar advice about five minutes before I checked this.
Page Index Toggle Pages: 1