Error: boolean is not a function

Student created a game and it was working. He then said it just stopped working without him making any changes. The error has always occurred on Line 52 saying “boolean is not a function”. He has tried moving blocks in his draw loop and it continues to put the error on line 52.

Hi, this looks like a link to a sign in page, not the game. Can you copy and paste the “Share” link from the project?


Sorry, I think this is the correct link!


In line 125, the student sets playerlose to true, but it is being called as a function in line 52. Once it is set to true, he can’t use it as a function anymore.


I’m not really sure how to help him fix it. He explained to me that he has it set like that so the playerlose function does not start during the instruction page. Once a key is pressed, he then wants the function to start. Any suggestions on other ways to go about doing what he wants. I’m just learning this stuff along with them!

Here’s what I would tell him: He identified a bug (that the function is running during the start screen), which is great, but the way that he tried to fix the bug (completely break the function by setting it to “false”) is not working. He needs to look back at the problem and figure out a different solution that only runs that function if the game has already started. He definitely knows how to do that, because he has written a function that sets the screen to the regular game once the program has already started.

The wider problem is the structure of how he does his start screen.

One great thing he is doing is to have a variable that changes when the “h” button is pressed, so the state of the game (started or not) is saved. However, the way that he has organized his code is confusing. There are a few things to consider when you have a start screen.

  1. Your general setup of the screen for the start, which should happen ONCE at the beginning of the game (e.g. setting visibility)
  2. All the stuff you want to CONTINUALLY happen before the game is started
  3. The things you want to happen ONCE when the game starts (e.g. setting visibility, placing sprites somewhere)
  4. The things you want to happen CONTINUALLY once the game has started (all the gameplay)

The original setup of the start screen should happen outside the draw loop at the beginning of the program. These things will run once when the program starts.

Inside the drawloop should be a conditional that checks the state of the game. If the game has not started, it should check to see whether the user has pressed the key to start the game, in this case the student’s startscreen function. If the game has started (the else condition), the program should run everything that happens continually during gameplay.

Inside the startscreen function, the program should check whether or not the relevant key has been pressed. If it hasn’t, it should run everything that it does continually during the start screen. If it has, it should both set the start variable to true (or add one to it in the case of this student), then do everything that it does ONCE when the game starts.

Here’s a vague example of that kind of code.

//setup the start screen
var gameStarted = false;

function draw() {
   // check if the game has started
   if (gameStarted) {
      // if it has started, just do normal gameplay
   } else {
      // if it hasn't started, check to see whether the user has pressed the start key

function startScreen() {
  if (keyWentDown("h")) {
    // if the user pressed h, start the game
    gameStarted = true;
    // normal gameplay setup to run once
  } else {
    // if the user has not pressed h, just do normal startup screen stuff

Notice that in this code, the program stops running the startscreen function once the game has started.

I know that’s a little much, but this is a complicated thing that he wants to do. Once way to think about it would be if he just made a program for the start screen, the code that went outside of the draw loop would be the startScreenSetup() code, and the code that went inside the draw loop would be the drawStartScreen() code. If he were just making a program for the main part of the game, the code outside of the draw loop would be the gameSetup() code and the code inside of the draw loop would be the regularGamePlay() code.


1 Like