How to use mouseX in a class?

Hello! I’m trying to use mouseX and mouseY inside a class. But when I use it, I get an error saying “‘mouseX’ was not declared in this scope” … Is there a simple fix for this?

 } else if(x > mouseX){   

yes, mouseX/Y is declared inside the ofBaseApp class so you can only access it from there, but theres a way to get a pointer to your app and access it’s members like:


or you can register your class to receive mouse events.

Thank you so much for answering! :slight_smile: I’m pretty sure I will make this work now, with your help. Thanks again! :slight_smile:

Hi arturo,

I have the same background as Rabbagast, in P5 we can call mouseX/Y from anywhere in the code, with no extra settings.

Can you elaborate a bit more, may be an example of the code in a class?

Many thanks

I get it now! always check the documentation before asking, my bad