How to reference an object in another function to its class?

1 way to do it: :angel:

Person squid;

void setup() {
  frameRate(1);
  squid = new Person();
}

void draw() {
  squid.increaseAge(); // alt.: ++squid.age;
  print(squid);
}

class Person {
  int age;

  Person increaseAge() {
    ++age;
    return this;
  }

  String toString() {
    return "Age: " + age + TAB;
  }
}
2 Likes