Let’s say that we have a class and a function (sorry for the peudo-code):
class Person
{
int age;
}
Person squid;
void IncreaseAge(Human object)
{
}
How would I make it so that I could do something like this:
void IncreaseAge(Human dataType)
{
squid.age += 1;
}
Thanks!
1 Like
1 way to do it:
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
Another more “functional” way, w/o a method:
Person squid;
void setup() {
frameRate(1);
squid = new Person();
}
void draw() {
increaseAge(squid); // alt.: ++squid.age;
print(squid);
}
Person increaseAge(final Person human) {
++human.age;
return human;
}
class Person {
int age;
String toString() {
return "Age: " + age + TAB;
}
}
2 Likes
glv
4
1 Like