java - Trying to create a dice in Processing but clicking is not triggering it -


i want make program show face of die after click in rectangle says "roll" when click, nothing happens.

can explain i'm doing wrong?

import java.util.random;  public random random = new random();  public color purple = #b507f5; public int dicechoose = random.nextint(6); public int x = mousex; public int y = mousey;   public void setup() {   size(750, 900);   background(255);  }  public void draw() {   strokeweight(3);    //dice roll button   rect(100, 700, 550, 150);   textsize(100);   fill(purple);   text("roll", 280, 815);   nofill();    //dice face   rect(100, 100, 550, 550);    roll(); }  public void one() {   fill(0);   ellipse(375, 375, 100, 100);   nofill(); }  public void two() {   fill(0);   ellipse(525, 225, 100, 100);   ellipse(225, 525, 100, 100);   nofill(); }  public void three() {   fill(0);   ellipse(375, 375, 100, 100);   ellipse(525, 225, 100, 100);   ellipse(225, 525, 100, 100);   nofill(); }  public void four() {   fill(0);   ellipse(525, 225, 100, 100);   ellipse(225, 525, 100, 100);   ellipse(525, 525, 100, 100);   ellipse(225, 225, 100, 100);   nofill(); }  public void five() {   fill(0);   ellipse(375, 375, 100, 100);   ellipse(525, 225, 100, 100);   ellipse(225, 525, 100, 100);   ellipse(525, 525, 100, 100);   ellipse(225, 225, 100, 100);   nofill(); }  public void six() {   fill(0);   ellipse(525, 225, 100, 100);   ellipse(225, 525, 100, 100);   ellipse(525, 525, 100, 100);   ellipse(225, 225, 100, 100);   ellipse(525, 375, 100, 100);   ellipse(225, 375, 100, 100);   nofill(); }  public void roll() {   if (mousepressed && x > 100 && x < 650 && y > 700 && y < 850) {     dicechoose = random.nextint(6);     if (dicechoose == 0) {       one();     }     else if (dicechoose == 1) {       two();     }     else if (dicechoose == 2) {       three();     }     else if (dicechoose == 3) {       four();     }     else if (dicechoose == 4) {       five();     }     else if (dicechoose == 5) {       six();     }   } } 

you set x , y variables equal mousex , mousey @ beginning of program. not mean when mousex or mousey change, x , y variables change too. consider this:

float x = 100; float y = x; x = 200; println(y); //prints 100! 

so instead of referring x , y (which never change), need use mousex , mousey in if statement:

  if (mousex > 100 && mousex < 650 && mousey > 700 && mousey < 850) { 

then have other issues (you don't detect click), answer first question.

by way, way figured out adding println() statements. put 1 before if statement , 1 inside of it:

  println("here 1");   if (x > 100 && x < 650 && y > 700 && y < 850) {     println("here 2");  

the "here 1" printed out, "here 2" did not, knew closer @ logic in if statements. in future, might try type of debugging yourself, save trouble of making post!


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

android - How to prevent keyboard from closing when bottom dialog is open? -