[the eternal] array index out of bounds
in
Programming Questions
•
1 year ago
if somebody with fresh eyes could help me...
just cant find what is happening.
The only way i managed to do it is to change the index of my array:
agenten = new Agent [number
-1]
but then i will have one agent less that i want.
Agent [] agenten;
PVector [] dir;
int number = int (random(5,10));
float ang = 2*PI/ number;
float c= cos(ang);
float s= sin(ang);
void setup() {
size(500, 500);
smooth();
agenten= new Agent[number];
dir = new PVector [number];
for (int i=0; i< agenten.length; i++) {
dir[i]=new PVector (cos(ang*i), sin (ang*i));
}
for (int i=0; i <= agenten.length; i++) {
agenten[i]=new Agent(width/2, height/2,random(dir[i].x,dir[i+1].x),random(dir[i].y,dir[i+1].y));
}
}
void draw() {
stroke (0);
background(255);
noFill();
for (int i=0; i<agenten.length; i++) {
agenten[i].render();
agenten[i].move();
}
void mousePressed() {
if (mousePressed = true) {
noLoop();}
}
1