Cannot find anything named "loc" error? Why?
in
Programming Questions
•
1 year ago
Hello, I'm working on a little project for school.
Eventually this program should have 'Agents' (ellipses) which are following my mouse movement. They should also bounce off black colored objects (this is not yet included in current coding).
This is my current code
Line 4 is where I define 'loc'
but at line1 of the other code part it gives the error: Cannot find anything named "loc"
Why?
Copy code
- class Agent {
- PVector loc = new PVector(width/2,height/2); //Here I defined "loc"
- PVector vel = new PVector(0, 0, 0);
- PVector acc = new PVector(1, 1, 0);
- Agent(PVector _loc) {
- loc = _loc;
- }
- void run() {
- display();
- update();
- followMouse();
- }
- void followMouse() {
- PVector target = new PVector(mouseX, mouseY, 0);
- PVector dif = PVector.sub(target,loc);
- float distance = dif.mag();
- dif.normalize();
- dif.div(100);
- acc.add(dif);
- }
- void update() {
- vel.add(acc);
- vel.limit(7);
- loc.add(vel);
- acc = new PVector();
- }
- void display() {
- stroke(0);
- fill(255);
- ellipse(loc.x, loc.y, 10, 10);
- }
- void botsen() {
- if ((loc.x == 622) || (loc.x == 25))
- {
- vel = vel*-1;
- }
- }
- }
Along with this:
Copy code
- Agent myAgent = new Agent(loc); // Error: "cannot find anything named "loc" " I defined "loc" above right?
- void setup() {
- size (647, 694);
- PImage img1;
- smooth();
- img1 = loadImage("Klembord01.gif");
- }
- void draw() {
- fill(255, 10);
- PImage img1;
- img1 = loadImage("Klembord01.gif");
- image(img1, 0, 0);
- a.run();
- }
Thanks in advance!
1