# Cannot convert from boolean to int

**URL:** <https://discourse.processing.org/t/cannot-convert-from-boolean-to-int/16218>\
**Category:** Beginners\
**Created:** [December 7, 2019, 2:20pm UTC](https://discourse.processing.org/t/cannot-convert-from-boolean-to-int/16218 "2019-12-07T14:20:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ardy2743](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@Ardy2743](https://discourse.processing.org/u/Ardy2743)\
**Post date:** [December 7, 2019, 2:20pm UTC](https://discourse.processing.org/t/cannot-convert-from-boolean-to-int/16218/1 "2019-12-07T14:20:31Z")

</div>

Hey! I’m new to Arduino and Processing I’m making a game and I want to play a certain sound when I or the CPU scores on Arduino.  
I’m getting the error **cannot convert from boolean to int** I don’t know what I’m doing wrong I do know the score++ is not working.

```auto
import processing.serial.*; // Import the Processing Serial Library for communicating with arduino
import ddf.minim.*;

Minim minim;

AudioPlayer sound1, sound2, sound3, sound4;

Serial myPort;              
int CPU_SCORE;
int PLAYER_SCORE;

boolean score = false;{
  
score++;
score = true;

}

 void setup()
{
  size(500, 500);
  println(Serial.list()); // Prints the list of serial available devices (Arduino should be on top of the list)
  myPort = new Serial(this, Serial.list()[1], 9600); // Open a new port and connect with Arduino at 9600 baud

  minim = new Minim(this);

  sound1 = minim.loadFile("roundLose.wav");
  sound2 = minim.loadFile("gameLose.wav");
  sound3 = minim.loadFile("gameWin.mp3");
  sound4 = minim.loadFile("roundWin.wav");
}
  

void draw()
{
  
  if(CPU_SCORE == 1 && score == true) {
    sound1.play();
    sound1.rewind();
    score = false;
  }
  
  if(CPU_SCORE == 2 && score == true) {
    sound1.play();
    sound1.rewind();
    score = false;
  }
    
  if(CPU_SCORE == 3 && score == true) {
    sound1.play();
    sound1.rewind();
    score = false;
  }

  if(CPU_SCORE == 4 && score == true) {
    sound1.play();
    sound1.rewind();
    score = false;
  }
  
  if(CPU_SCORE == 5 && score == true) {
    sound1.play();
    sound1.rewind();
    score = false;
  }
  
 if(CPU_SCORE == 6 && score == true) {
    sound1.play();
    sound1.rewind();
    score = false;
  }
  
  if(CPU_SCORE == 7 && score == true) {
    sound1.play();
    sound1.rewind();
    score = false;
  }

  if(CPU_SCORE == 8 && score == true) {
    sound2.play();
    sound2.rewind();
    score = false;
  }
  
  print(CPU_SCORE);
  println(PLAYER_SCORE);
  
 }
  

void serialEvent(Serial myPort) // Is called everytime there is new data to read
{
  if (myPort.available() > 1)
  {
    String completeString = myPort.readStringUntil(10); // Read the Serial port until there is a linefeed/carriage return
    if (completeString != null) // If there is valid data insode the String
    {
      trim(completeString); // Remove whitespace characters at the beginning and end of the string
      String seperateValues[] = split(completeString, ","); // Split the string everytime a delimiter is received
      CPU_SCORE = int(seperateValues[0]);
      PLAYER_SCORE = int(seperateValues[1]);
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 7, 2019, 4:42pm UTC](https://discourse.processing.org/t/cannot-convert-from-boolean-to-int/16218/2 "2019-12-07T16:42:13Z")

</div>

> [@Ardy2743](#):
>
> boolean score = false;

when you say

```auto
boolean score = false;

```

score is either true or false

Hence you cannot say

```auto
score++;

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 7, 2019, 4:43pm UTC](https://discourse.processing.org/t/cannot-convert-from-boolean-to-int/16218/3 "2019-12-07T16:43:27Z")

</div>

> [@Ardy2743](#):
>
> boolean score = false;
> 
> { score++;  
> score = true;  
> }

You don’t need brackets {} here

just say

`boolean score = true;`

---

<div class="post-metadata">

**Author:** ![Ardy2743](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@Ardy2743](https://discourse.processing.org/u/Ardy2743)\
**Post date:** [December 7, 2019, 4:55pm UTC](https://discourse.processing.org/t/cannot-convert-from-boolean-to-int/16218/4 "2019-12-07T16:55:23Z")

</div>

Thank you for your responce! and again i am crap at explaining what the issue is! So in my game im trying to get a sound to play everytime either I or the CPU score (I’m only working on CPU at the moment) but when the CPU scores it will play the sound once. Then it for score 2,3,4,5,6,7,8 nothing so I was told to do this.

![1](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1f6f621750c107634bdb4c642be19ba1cfc178c5.png)

I’m really new to the code and i was looking up a tutorial on how to implement it but I don’t think i don’t it right. 😅

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [December 7, 2019, 5:07pm UTC](https://discourse.processing.org/t/cannot-convert-from-boolean-to-int/16218/5 "2019-12-07T17:07:23Z")

</div>

You‘re not doing what is shown in the image.  
You‘re checking if you want to be playing the sound each frame if the score equals to a number and then set the bool to false, stopping every if statement from being called…

What you need to do is described in the image, so i won‘t describe it again. But i‘ll give you some hints.

In draw you have to check if the current CPU\_Score is bigger than the last CPU\_Score. If it is, you set the bool to true.

Likewise in draw you check if the bool is true. If it is, you Play the sound and set the bool to false again, to avoid it playing again each frame.

Also, this statement Here :

```auto

boolean score = false;{
  
score++;
score = true;

}

```

This is wrong. It will not work… That‘s also where you got that error from. That part makes no sense, so the Compiler just threw the first error it could get there.

---

<div class="post-metadata">

**Author:** ![Ardy2743](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@Ardy2743](https://discourse.processing.org/u/Ardy2743)\
**Post date:** [December 7, 2019, 5:15pm UTC](https://discourse.processing.org/t/cannot-convert-from-boolean-to-int/16218/6 "2019-12-07T17:15:52Z")

</div>

Thank you for your responce! I understand what your saying to do (I think) but i do not know how to code it.

![dont know](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/20d58c7269bd903811a1b8ff8ad942aa122b057d.png)

This is the part that is throwing me a little. I do know how to write that.

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [December 7, 2019, 6:05pm UTC](https://discourse.processing.org/t/cannot-convert-from-boolean-to-int/16218/7 "2019-12-07T18:05:15Z")

</div>

Just add a global variable previousCPU\_Score and set it to 0.

In draw, check if the CPU\_Score is bigger than previousCPU\_Score. If it is, then trigger the sound and set previousCPU\_Score to CPU\_Score.

---

<div class="post-metadata">

**Author:** ![Ardy2743](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@Ardy2743](https://discourse.processing.org/u/Ardy2743)\
**Post date:** [December 7, 2019, 6:09pm UTC](https://discourse.processing.org/t/cannot-convert-from-boolean-to-int/16218/8 "2019-12-07T18:09:09Z")

</div>

Okay i got that thank you!
