Help with class and draw

#1

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

#2

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 .

https://www.processing.org/reference/dot.html

Read more about OOP / objects in the tutorial :

https://www.processing.org/tutorials/objects/

1 Like
#3

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

#4

is lvl an int?

This works:

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

maybe show a bit of your class?

#5

class frisk
{

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

#6

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

#7

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

you need a object of this class

(lv or lvl ?)

#8

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

in the start of my program

#9

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
#10

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

#11

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