Cannot convert from boolean to int

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.

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]);
    }
  }
}
1 Like

when you say

boolean score = false;

score is either true or false

Hence you cannot say

score++;

You don’t need brackets {} here

just say

boolean score = true;

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

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. :sweat_smile:

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 :


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.

1 Like

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

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

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.

2 Likes

Okay i got that thank you!

1 Like