toggle problems JS

Hello im trying to toggle a boolean on and off. But it doesn’t work any idea why?
Error: Cannot convert ‘boolean’ to ‘UnityEngine.CursorLockMode’.

script:

if(Input.GetKeyDown(KeyCode.Escape))
	{
		displayConsole = !displayConsole;
	}

	//Console Controller
	if(displayConsole)
	{
		Cursor.visible = true;
		Cursor.lockState = false;
	}
	else
	{
		Cursor.lockState = true;
		Cursor.visible = false;
	}

You’re getting the error because you’re trying to assign a boolean value to Cursor.lockstate. Cursor.lockstate is of the data type CursorLockMode, so you have to assign it one of these three values.

  1. CursorLockMode.None - cursor isn’t locked.
  2. CursorLockMode.Locked - cursor is locked to the center of the screen
  3. CursorLockMode.Confined - cursor is confined to the game window.

Hi,
I tried your code and as LazyElephant said it is linked to using a boolean for your cursor state
This should work

var displayConsole : boolean;


function Update()
{
if(Input.GetKeyDown(KeyCode.Escape))
     {
     SetCursor();
     displayConsole = !displayConsole;
     }
 }

function SetCursor()
{	 	
 //Console Controller
 if(!displayConsole)
 	{
     Cursor.visible = true;
     Cursor.lockState = CursorLockMode.None ;
 	}
 else
 	{
     Cursor.lockState = CursorLockMode.Locked;
     Cursor.visible = false;
 	}
}

but please note that the lock cursor itself doesn’t seem to work well at least in unity - not sure about in the build. http://forum.unity3d.com/threads/cursor-lockstate-troubles.278221/
I would recommend you put a “plane” under your console which will appear with it an block all potential raycast or button hits your mouse will do.
hope that helps,