keyPressed & waiting for input

9 views
Skip to first unread message

emf...@gmail.com

unread,
May 5, 2018, 6:07:11 AM5/5/18
to Processing.js
I'm running the following code, but want the code to stop on the initial screen until a key is pressed, which it doesn't appear to do.

{
    background(139,139,139);
    keyPressed=false;
    text("Now input on the keyboard your vehicle type - a for lorry, b for car or c for pedestrian",150,150);
    text("You want the most vehicles on the bridge without causing excessive bending stresses - be careful!",200,150);
   
    if (keyPressed==true)
    {
      if (key=='a'||key=='A')
      {
        VehicleType="Lorry";
        VSelect="Complete";
        keyPressed=false;
      }
      if (key=='b'||key=='B')
      {
        VehicleType="Car";
        VSelect="Complete";
        keyPressed=false;
      }
      if (key=='c'||key=='C')
      {
        VehicleType="Ped";
        VSelect="Complete";
        keyPressed=false;
      }
      else
      {
        text("Invalid selection.",150,150);
        VSelect="Incomplete";
        keyPressed=false;
      }
    }
    else
    {
      background(206,59,19);
      text("Get on with it",150,150);
      VSelect="Start";
    }
   
    if (VSelect=="Incomplete")
    {
      background(139,139,139);
      text("Please input a proper vehicle type - a for lorry, b for car or c for pedestrian",150,150);
     
Reply all
Reply to author
Forward
0 new messages