|
Author |
Topic: declaring relative to height. (Read 599 times) |
|
benelek
|
declaring relative to height.
« on: Jan 8th, 2003, 1:25pm » |
|
ok, so this's my lack of knowledge about the order of compilation, but here's a question: how come, when i declare a variable, say, outside of a procedure, and i define it relative to height, the height is given as 0. for example: Code: void setup() { size(200,200); } int a = width; int b = height; void loop() { println(a + ', ' + b); } |
| this code will print out the line "0, 0" in proce55ing. obviously the variables a and b have been declared by the time loop() is called, otherwise an error would be given. and aren't all variables created only after the size() is given? is there a magic veil hanging between the workings of proce55ing and my eyes? is this a bug? should i go to bed? (yes) -jacob
|
|
|
|
fry
|
Re: declaring relative to height.
« Reply #1 on: Jan 8th, 2003, 2:39pm » |
|
variables declared outside a function that have definitions, eg. a = width, or a = 3, will be defined when the class is created. this means that before anything is run, the variable is set. so in this case, by the time setup() is called, a and b are already set to 'width' and 'height', which have no value set for them. why not just use width and height? you're right, size() sets all the graphics-oriented variables, but because a and b are being assigned to the current value of width/height at startup, they just wind up being zero. (note that this isn't just a p5 thing, it's built into java and c++ and most other languages as such..)
|
« Last Edit: Jan 8th, 2003, 2:40pm by fry » |
|
|
|
|
|