FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Bugs
   Bug Fixes, Implemented Suggestions
(Moderator: fry)
   0046: random() failing inside classes (p46)
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: 0046: random() failing inside classes (p46)  (Read 316 times)
Glen Murphy

WWW Email
0046: random() failing inside classes (p46)
« on: Dec 2nd, 2002, 6:45am »

While I've used random() in other projects often without fail, if I uncomment the 'float r = random(50);', the applet window fails to appear, with no error messages.
 
(this code is a mutilated version of working code, just to show the error).
 
 
////////////////////////
 
int WIDTH = 500;
int HEIGHT = 500;
int NUMMINES = 6;
 
Mine mine[] = new Mine[NUMMINES];
 
class Mine {
  int NUMSPOKES = 12;
  
  float x, y, size;
  Spoke spoke[] = new Spoke[NUMSPOKES];
  
  Mine(float xIn, float yIn, float sizeIn) {
    x = xIn;
    y = yIn;
    size = sizeIn;
    for(int i = 0; i < NUMSPOKES; i++) {
      //float r = random(50);
      spoke[i] = new Spoke(size+i, i*5, i);
      }
    }
  }
 
class Spoke {
  float dist, dir, dirVel;
  
  Spoke(float distIn, float dirIn, float dirVelIn) {
    }
  }
 
void setup() {
  size(500,500);
  ellipseMode(CENTER_DIAMETER);
  
  for(int i = 0; i < NUMMINES; i++) {
    mine[i] = new Mine(random(0,WIDTH), random(0,HEIGHT), random(10,30));
    }
  }
 
void loop() {
 
  }
//////////////////////////
 
(edit: added version number to title, for future reference)
« Last Edit: Dec 9th, 2002, 6:00am by Glen Murphy »  
REAS

WWW
Re: random() failing inside classes (p46)
« Reply #1 on: Dec 2nd, 2002, 6:23pm »

Yes, I've just recently seen this too. It only fails within the constructor. For a temporary workaround, you can make a new class method (that is called in the constructor) for setting your random values.
 
fry


WWW
Re: random() failing inside classes (p46)
« Reply #2 on: Dec 2nd, 2002, 8:09pm »

that's really odd.. i'll look into it.
 
Glen Murphy

WWW Email
Re: 0046: random() failing inside classes (p46)
« Reply #3 on: Dec 10th, 2002, 11:15pm »

In addition, the same thing happens when using print / println within a constructor.
 
fry


WWW
Re: 0046: random() failing inside classes (p46)
« Reply #4 on: Aug 15th, 2003, 6:48pm »

the p5 functions inside constructors issue should now be taken care of (as of 57/5
 
Pages: 1 

« Previous topic | Next topic »