Problem with global variables and array
Hello,
I'm having problems trying to reach a variable set inside a Class, here is my code:
- //declaration of object
- Colores unColor;
- void setup()
- {
- size(100, 300);
- smooth();
- frameRate(60);
- background(226,225,215);
- noFill();
- // building array of colors
- Colores colores = new Colores();
- colores.buildColorTable();
- //creation of object
- unColor = new Colores();
- //prints result
- println(unColor.devuelveColor());
- }
- //----------- Class Colores -------->
- public class Colores {
- color elcolor;
- PImage imagenDelMarActual;
- int numColors = 100;
- color[] coloress = new color[numColors];
- int puntoX=100;
- int puntoY=50;
- Colores() {
- imagenDelMarActual = loadImage("elmar.jpg");
- }
- void buildColorTable() {
- elcolor = imagenDelMarActual.get(100,300);
- float elrojo = red(elcolor);
- float elverde = green(elcolor);
- float elazul = blue(elcolor);
- coloress[1] = color(117, 144, 173);
- coloress[2] = color(82, 112, 138);
- coloress[3] = color(82, 12, 18);
- }
- // the problem is here it returns 0 and not the color value
- color devuelveColor() {
- return coloress[2];
- }
- }
Can anyone tell me why devuelveColor() is returning 0?
I don’t really understand how to declare global variables inside a Class
It’s possible to declare a variable inside a class and get the data in another class?
I hope that my English is clear enough ; )
Thanks in advance!
Goza