- Home /
getting a error with a switch statement
i'm trying to make a switch statement but i'm getting 3 error lines on 1 line of code, the error's say "operator '==' cannot be used with a left hand side of type 'system.type' and a right hand side of type 'PlayerState'. (BCE0051)" i'm new to coding so i havent got a clue, any help would be much appriciated`
enum PlayerState
{
schaaplinks = 0,
schaaprechts = 1,
schaaplinksspring = 2,
schaaprechtsspring = 3,
}
var playerState = PlayerState.schaaplinks;
var lives : int = 3;
var key : int = 0;
var coins : int = 0;
var projectiellazer : GameObject;
var projectielslotlinks : Transform;
var projectielslotrechts : Transform;
var schaaplinks : Material;
var schaaprechts : Material;
var veranderschaap : boolean = false;
var kijktlinks : boolean = false;
private var coinlive : int = 20;
private var canshoot : boolean = false;
function Update ()
{}
function Addkeys ( numkey : int )
{
key += numkey;
}
function Addcoins ( numcoins : int )
{
coins = coins + numcoins;
}
function setPlayerState ()
{
var playerControls = GetComponent ( "playerControls" );
var charController = GetComponent ( CharacterController );
switch ( PlayerState )
{
case PlayerState.schaaplinks :
break;
case PlayerState.shaaprechts :
break;
case PlayerState.schaaplinksspring :
break;
case PlayerState.schaaprechtsspring :
break;
Answer by Dave-Carlile · Jan 03, 2013 at 07:46 PM
PlayerState (upper case 'P') is an enumerated type. The variable you want to use in your switch statement is playerState (lowercase 'p').
allright now i got rid of 2 of the errors but one still remains
I assume you have a closing } at the end of your switch statement.
switch (playerState)
{
} <-- this isn't in your code sample
"operator '==' cannot be used with a left hand side of type 'system.type' and a right hand side of type 'PlayerState'. (BCE0051)" that is the error and it is on "switch ( playerState )"
Can you add a comment with your latest code? Just the switch statement. The entire statement if possible.
Answer by Piflik · Jan 03, 2013 at 07:47 PM
You use the Enum Type as variable in the switch statement, instead of the variable of the type PlayerState.
switch(playerState) {
//....
}
and not
switch(PlayerState) {
//....
}
Also, please format your code properly on future posts. An unformatted script is nigh illegible.
thank you but onfortunaetly there is still one error left