Help with class and draw

Hi, I have a class with the variable lvl=1;.
the problem is I want to display the “1” in draw by doing something like this:
text(“lvl”,200,200,100,100);
however this doesn’t work

Try


 text( objectName.lvl,200,200,100,100);

instead

it’s objectName then a dot and the lvl

More Info

Read more about the dot .

Read more about OOP / objects in the tutorial :

1 Like

I have tried but it just says:
the function “text()” expects parameters like: "text(char[],int,int,float,float);

is lvl an int?

This works:

size(555, 555);
text( 8, 200, 200);

maybe show a bit of your class?

class frisk
{

int x;
int lv=1;
int exp;
int hp=20;
int maxhp=20;
}

and i wrote " text(frisk.lv,150,700,70,70);"

frisk is the class name (convention: should be Frisk with capital letter F)

you need a object of this class

(lv or lvl ?)

it is lv… whoops
and i wrote:
frisk frisk;

in the start of my program

this looks not good: frisk frisk;

this works:



Frisk frisk1=new Frisk(); 

void setup() {
  size(555, 555);
  text( frisk1.lv, 200, 200);
}

class Frisk {
  int x;
  int lv=2;
  int exp;
  int hp=20;
  int maxhp=20;
}
1 Like

thank you but can you tell me what:
“Frisk frisk1=new Frisk();” does?

The class Frisk (capital letter F) is the cookie maker (= class), the frisk1 (small letter f) is the cookie (= one object instantiated from the class). In this line we make a cookie.

You can have many cookies derived from the same class.

See tutorial I linked to above…

4 Likes