Mouse clicking and database questions?

Hi there! I've spent a long time trying to figure out how I can get my database and my mouse clicks to work. If someone could help me with it I would appreciate it so much. What I want to do is get the buttons on the side to individually have their own information from the database. When I use my mouse click command it goes on all three of the buttons but I want it to only work on one each. When you click on a button I wanted it to grab something from the database I've made so the first button would be the first bit in my database then where the database is spaced, that's for the second button. I'm quite confused on how to do this and my video is now not working as well (it's meant to tint to the jellyfish and it). If someone could help it would be great!

http://alpha.editor.p5js.org/Jaz/sketches/rkNRPAuqb

Answers

  • you can write your 3d botton shorter by the way:

      fill(0);
      textAlign(CENTER, TOP);
      text("Relationships between\n"+
                 "jellies & other organisms",115,470);
    

    The \n means new line

    You could also write:

      fill(0);
      textAlign(CENTER, TOP);
      text("Relationships between\njellies & other organisms",115,470);
    

    Your Question

    Check the mouse position against the burrons

    eg.

    if (mouseIsPressed)
        if (dist(mouseX,mouseY,115,470) < 45) {
             // 3rd button !!!
        }
    

    next step I recommend a small variable that tells what entry of database to show:

    (this must be before setup())

    int stateEntry = 0; // show no entry
    

    so if stateEntry would be 3 you show the info on "Relationships between jellies & other organisms" for example

    so the above code would be

       if (mouseIsPressed)
        if (dist(mouseX,mouseY,115,470) < 45) {
             // 3rd button !!!
             stateEntry = 3; 
        }
    

    OK.

    Now in draw evaluate stateEntry

    //evaluate 
    if(stateEntry == 0 ) {
        //do nothing
    }
    else if(stateEntry == 3 ) {
        //show database on "Relationships between jellies & other organisms"
        // ..............
    }
    

    Hope this helps.

    Chrisir ;-)

  • Hey Chrisir, the buttons now work but on p5js int stateEntry is put like int(stateEntry = 0); IN the setup apparently according to it. I have no idea how to work around this because it still wont work http://alpha.editor.p5js.org/Jaz/sketches/rkNRPAuqb

  • Sorry you got it wrong

    stateEntry : declare it before setup

    In draw: separate strictly where you read mouse and where you evaluate entryState

Sign In or Register to comment.