My compiles began taking too long and my sketch seems to require too many mouse clicks to actually perform the mouse click function. I am thinking that this is a memory problem so I increased the maximum memory available to 800 MB. No change that I could see.
What are the recommendations for setting maximum memory?
Hi @fredstout,
That’s too less information to give a qualified answer.
If the event handling ie. mouse clicks gets processed slow this is not necessarily a memory issue.
Tell or show a bit more what you are currently doing in your code and let us know what you’re trying to achieve…
Cheers
— mnse
Thank you for your prompt response. In looking at your response, it occurred to me that I really asked two questions:
-
What is the guidance relative to the maximum memory option under preferences?
-
Why is my mouse so slow? My first reaction was to think that I had put too much code in the mouseClicked function. I think of the mouseClick function as an interrupt service routine and that it should be as small (read quick) as possible. I rewrote it as follows (sorry, I can’t find the code formatter control)
This sketch is a Bingo Sketch, Ball numbers are displayed on the screen and when selected (mouse) they are highlighted. There are other options:
//MOUSECLICKED////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void mouseClicked (){
int x = 0,i;
float xd = BoxWidth/2 * .95;
float yd = BoxHeight/2 * .95;
boolean nb = false;
//… Clicking upper left corner of the screen is a prompt(quick) exit
if (TRACE) println ("mouseClicked: Mouse: " + mouseX + “/” + mouseY);
if (mouseX < 20 && mouseY < 20){
ExitNow = true;
return;
}
//… Check for a ball selection
BallSelected = false;
for (x = 1; x < 76; x++){
if (mouseX > BoxX - xd && mouseX < BoxX + xd && mouseY > BoxY - yd && mouseY < BoxY + yd){
BallSelected = true;
NewBall = x;
if (TRACE) println (" new ball: " + x);
ScreenChange = true;
break;
}
}
if (BallSelected) return;
// if a ball was not selected, check for command
//***************************************** G O B A C K 1 B A L L **************************************************
if (PB_Back.Selected()){
if (LastBall == -1) {
NewGame();
ClearScreen();
return;
}
PB_Back.On(Green);
Backone = true;
return;
}
//*********************************************** N E W G A M E ********************************************************
if (PB_New.Selected()){
NewGame();
ClearScreen();
ScreenChange = false;
return;
}
//***************************************************** E X I T ************************************************************
if (PB_Exit.Selected()) Close();
//**************** N O M O N E Y B A L L O R W I L D C A R D I F G A M E R U N N I N G ******************
if (GameRunning) return;
//************************************************ M O N E Y B A L L ******************************************************
if (PB_Moneyball.Selected()){
Moneyball = !Moneyball;
if (TRACE) println ("MB Pushbutton: " + Moneyball + " ball: " + MoneyBall);
if (Moneyball == false){
PB_Moneyball.label(“MB”);
PB_Moneyball.Off(Red);
} else {
PB_Moneyball.label(nf(MoneyBall,0));
PB_Moneyball.On(Green);
}
ScreenChange = true;
return;
}
//*********************************************** W I L D C A R D ********************************************************
if (PB_Wildcard.Selected()){
Wildcard = !Wildcard;
if (TRACE == true) println ("WC Pushbutton: " + Wildcard + " ball: " + Wildcard);
if (Wildcard == false) {
PB_Wildcard.Off(Red);
} else {
WildCard = LeastSignificant (BaseNumber(“WC”), “WC”); // generates a new wild card number (0 - 9
PB_Wildcard.On(Green);
}
ScreenChange = true;
return;
}
}//…End of Mouseclicked
// MOUSECLICKED
void mouseClicked() {
int x = 0, i;
float xd = BoxWidth/2 * .95;
float yd = BoxHeight/2 * .95;
boolean nb = false;
//..... Clicking upper left corner of the screen is a prompt(quick) exit
if (TRACE) println ("mouseClicked: Mouse: " + mouseX + "/" + mouseY);
if (mouseX < 20 && mouseY < 20) {
ExitNow = true;
return;
}
//..... Check for a ball selection
BallSelected = false;
for (x = 1; x < 76; x++) {
if (mouseX > BoxX[x] - xd && mouseX < BoxX[x] + xd && mouseY > BoxY[x] - yd && mouseY < BoxY[x] + yd) {
BallSelected = true;
NewBall = x;
if (TRACE) println (" new ball: " + x);
ScreenChange = true;
break;
}
}
if (BallSelected) return;
// if a ball was not selected, check for command
/***************************************** G O B A C K 1 B A L L **************************************************/
if (PB_Back.Selected()) {
if (LastBall == -1) {
NewGame();
ClearScreen();
return;
}
PB_Back.On(Green);
Backone = true;
return;
}
/*********************************************** N E W G A M E ********************************************************/
if (PB_New.Selected()) {
NewGame();
ClearScreen();
ScreenChange = false;
return;
}
/***************************************************** E X I T ************************************************************/
if (PB_Exit.Selected()) Close();
/**************** N O M O N E Y B A L L O R W I L D C A R D I F G A M E R U N N I N G ******************/
if (GameRunning) return;
/************************************************ M O N E Y B A L L ******************************************************/
if (PB_Moneyball.Selected()) {
Moneyball = !Moneyball;
if (TRACE) println ("MB Pushbutton: " + Moneyball + " ball: " + MoneyBall);
if (Moneyball == false) {
PB_Moneyball.label("MB");
PB_Moneyball.Off(Red);
} else {
PB_Moneyball.label(nf(MoneyBall, 0));
PB_Moneyball.On(Green);
}
ScreenChange = true;
return;
}
/*********************************************** W I L D C A R D ********************************************************/
if (PB_Wildcard.Selected()) {
Wildcard = !Wildcard;
if (TRACE == true) println ("WC Pushbutton: " + Wildcard + " ball: " + Wildcard);
if (Wildcard == false) {
PB_Wildcard.Off(Red);
} else {
WildCard = LeastSignificant (BaseNumber("WC"), "WC"); // generates a new wild card number (0 - 9
PB_Wildcard.On(Green);
}
ScreenChange = true;
return;
}
}
//....End of Mouseclicked
EDIT: Add formatted Code (mnse)
Hi @fredstout,
Will have a look tomorrow, but please follow the rule from below first…
Cheers
— mnse
We kindly ask you to please format your code. This will make it easier for other community members to help you. If you need help you can check the FAQ section on code formatting. Thanks!
I realize the need to format code, I want to do that, and I read the instructions but there is no format control to enable me to do that.
Hi @fredstout,
I’ve added a formatted version of your code below yours. Please remove the unformatted one.
I would say … As long you’re not getting an error which says that the VM runs out of heap space, leave it as it is by default.
Hard to say, without testing the whole program and see the effective result to find the bottleneck.
From a first sight, the code in the mouse handling, even if it is as long as yours, shouldn’t be an issue, at lease if you are not acting on it like on an idle clicker game. I would use mousePressed or mouseReleased function instead mouseClicked, as mouseClicked gets triggered after a combined mousePressed/mouseReleased action, but this also shouldn’t be an issue.
Cheers
— mnse
In some cases the </>
button may not appear immediately. In this case you will find the option under the gear icon (the last button to the right on the editor’s header bar). I updated the FAQ to clarify this.
Thank you for your assistance, it is greatly appreciated. I changed the code to use mousepressed and it did seem to operate better than before. Thank you.