if statement issue not working

edited May 2014 in Questions about Code

ok, for my program im doing an if statement, every time i have put "keyPressed" into use instead of just "key" there is always an error, here is my code

       if(ypos>=160 && keyPressed == 'w')



  • edited May 2014 Answer ✓

    Variable keyPressed is of type boolean, not a char or int!!! :-w

  • Well i might not know that!!! That's why i asked the question!!! [-X

  • Hey Chacka,

    It's a very common mistake. As a general rule of thumb and as common courtesy, be sure to make 99.99% sure it isn't a type error or something small. We want to help you tackle good problems, not debug small errors.

    You don't like em. And we don't like em. But it's your code =).

  • edited May 2014

    Well i might not know that!!! That's why i asked the question!!!

    Sorry for somewhat moody reply. But posting the error message would made things a lil' clearer too: 8-X

    The operator == is undefined for the argument type(s) boolean, char.

  • well im very new to this whole thing and am trying to learn as i go along while making something really cool, i cant tell you how many times i have allready missed things like brackets and semi colons, and for my problems ive been using the float data type mainly, do i have to use boolean? i will show you my whole code and also the reference part of the processing website is really confusing to me, and how do i add values to boolean would it just be boolean a = 100; ????

    Person myperson; 
    float locx=300;
    float locy=-100;
    float locz=300;
    //PVector location;
    //boolean a = false;
    void setup() { 
      myperson = new Person(100, 100, 100, 0.0, 0.00,0,.1,300,-50,300);
      //location = new PVector(1.5,2.1);
    void draw() {
      background(155, 155, 30); 
      if(ypos>=165 &&  keyPressed == 'w')
        gravity =-10;
    class Person {
      float xpos; 
      float ypos; 
      float zpos; 
      float xspeed; 
      float yspeed; 
      float zspeed;
      float gravity;
      float locationx;
      float locationy;
      float locationz;
      Person(float tempxpos, float tempypos, float tempzpos, 
      float tempxspeed, float tempyspeed, float tempzspeed , float
     tempgravity ,float templocationx  ,float templocationy ,
     float templocationz)
        xpos = tempxpos; 
        ypos = tempypos; 
        zpos = tempzpos; 
        xspeed = tempxspeed; 
        yspeed = tempyspeed; 
        zspeed = tempzspeed;
        gravity = tempgravity;
        locationx = xpos;
        locationy = ypos;
        locationz = zpos;
      void display() { 
       // camera(xpos,ypos,zpos,height/2,0,0,1,0);
        fill(255, 50, 50);
        translate(xpos, ypos, zpos);
      void move() { 
        xpos = xpos + xspeed; 
        ypos = ypos + (gravity*10); 
        zpos = zpos + zspeed;
    if(ypos>= 168)
    gravity = 0;
    ypos= 168;
     gravity = .1;
    //for camera ground
    if(ypos>=165 && keyPressed == 'w')
      gravity = -10;
          xpos = xpos + 3;
          locx = locx+3;
          xpos = xpos-3;
          locx = locx-3;
          ypos = ypos - 4;
          locy = locy - 4;
          ypos = ypos+4;
          locy = locy+4;
          case (UP):
          zpos = zpos - 5;
          locz = locz - 5;
          case (DOWN):
          zpos = zpos + 5;
          locz = locz +5;
  • edited May 2014 Answer ✓

    Fail to compile due to Cannot find anything named "ypos"!

    ive been using the float data type mainly,

    Datatype float is the right choice if some1 doesn't wanna worry about the most adequate for a particular situation!
    Java provides 8 primitive types. You can see most of it in the section Primitive in the reference page:

    do i have to use boolean?

    We can declare our own variables w/ the type we wish or need!
    However, keyPressed was declared and is controlled by the Processing's framework!
    So if we wanna deal w/ it, we gotta take into consideration that it's of boolean type!

    ... and also the reference part of the processing website is really confusing to me,

    It's divided by sections rather than alphabetically ordered!
    Use CTRL+F in your browser to find the API you're searching for.

    ... and how do i add values to boolean would it just be boolean a = 100; ????

    Have you read the link I've left for ya and you had accept as answer in my 1st reply???

  • thankyou for your help! i know im being difficult... i will read everything a little bit more finely and through all the data types, and i know about the ref page i meant the explanations to everything, simpleshapes like rect are straight forward, but class takes more infering which took me a while to figure out, i may post more questions but keep in mind this is my first time learning a computer language and that i started last week, one thing i have figured out is this is a very mathematically inclined piece of software and can be a bit tedious when there are dozens of numbers going everywhere especially in p3d ~X( but thankyou for your help and support! :D

  • it's just key=='w' of course

    there are different data types

    for sentences and words String

    for numbers mostly float (for screen pos)

    for numbers when you want to count (whole numbers) int

    for when it can be only true or false it's boolean

    you're doing great !

Sign In or Register to comment.