"cannot convert from void to boolean" mystery ...

edited July 2014 in Questions about Code

Hi everyone!

My problem is a mystery to solve! I was trying learning Casey Reas Compendium here peepproject.com/tutorials/tutorial/25/view, which have is own running interface as you see... Everything is working in this interface, but not in MY processing programme... I have updated yesterday to the last version, maybe is the reason why, but this part of code doesn't want to work :

for(int i=0; i<circles.length;i++){
      Circle other=circles[i];
        if(touching(other)){    //here is the error message

And this beautiful message appears... but not in the running window on the website... SO... If anyone can explain me why it would be really cool! :) Is it a modification due to update version?

Thanks a lot! Have a beautiful night!



  • edited July 2014 Answer ✓

    Can you show us the "touching" method? If you're running this in Processing (not on a web-page, or anything like that. Just Processing.), then you're doing something wrong. Although let me take a look at the code.

  • Nonono. My comment is NOT an answer.

  • here there is :

    void touching(Circle other){
      return (distance(other)<radius+other.radius);
    float distance(Circle other){
      return dist(x,y,other.x,other.y);

    I'm not sure to understand, I started few weeks ago to learn so ... but are you saying it's because in MY processing i'm running the sketch in JAVA mode only when the website is in JAVASCRIPT mode ? :/

  • sorry ^^ I'm new here and a window jumped on my face telling me to choose, I panicked , thought it was for choosing if the comment was visible but I understood my mistake after done it -_-' sorry again

  • edited July 2014

    Well, there's your problem. Let me give you a quick lesson, in case you don't understand.

    Take a look at the "touching" method. The prefix is 'void'. That (as you probably know) means that if you give data, or even try to execute it in a line of code, you will get nothing in return.

    I am unsure why the exception wasn't thrown at the return statement of "touching", but your method isn't returning anything at all. Try changing the 'void' to 'boolean'.

    P.S. It's fine. You aren't alone in the fact that you've pressed the accept button. 3 other people prior to you have done this today, in posts that I've been trying to give answers to.

  • I thought about this solution, actually, it seems clear to me there was a mistake( and that turning void to boolean was the solution! (Y) proud of myself ^^) , but in this case, why is it working on the website window ? it's really weird no?

    also thanks for the lesson it clears what was an intuition in my mind :)

  • ...are you saying it's because in MY processing i'm running the sketch in JAVA mode only when the website is in JAVASCRIPT mode?

    I'm not saying anything. It's just that anything that lies in the field of Javascript isn't very familiar territory to me. But I know a lot about Java, so if it doesn't work in Processing, then it's the coder's 'fault' (bit of a rough word).

  • It is probably working fine in the window due to a more low-level translation, which just eliminates any prefixes altogether. But don't quote me on that. I'm not sure.

  • Aaaand... my theory stands! I am able to return an integer from a method that is supposed to return a boolean.

    So. Please. Do not use that, unless you have a need for multi-type returning.

  • However, now it's working on my processing, problem solved, and basic knowledges consolidated! ^^

    Thank you a lot :)

  • Okay :)

  • edited July 2014

    In JavaScript, variables themselves got no type declaration. All variables can hold any type of value!
    Likewise, functions got neither parameter nor returning declared types!
    It means that: return distance(other) < radius+other.radius; is always gonna return a boolean.
    The void part is discarded when a Java Mode app is run in JavaScript Mode!
    Actually, all type declarations are discarded! >:)

  • Thanks for the complementary explanation ;)

Sign In or Register to comment.