error BCE0022: Cannot convert

Hello all,

I’m relatively new to Unity could use some help. I’ll try to be as specific concise as possible…

I have a pathNode.js script that has the following:

/*
Path node helper
Description: help control the logic of the enemy as it moves in the world
*/
enum PathInstruction{moveLeft=0, moveRight=1, moveStop=2, jumpAir=3}
var pathInstruction = PathInstruction.moveStop;

function OnTriggerEnter (other : Collider)
{
	if(other.tag == "enemy")
	{
		print("default case from pathNode.js: " + pathInstruction);
		/*this is functional*/
	}
}

On a separate enemyGumba.js, I am trying to call pathInstruction assign it to my gumbaState with the following lines:

/*Global variables*/
enum GumbaState{moveLeft=0, moveRight=1, moveStop=2, jumpAir=3, enemyDie=4, goHome=5}
/*basic movements*/
var gumbaState = GumbaState.moveLeft;
/*sets the default state in the inspector*/
:
/*end global variables*/

function OnTriggerEnter (other : Collider)
{
	/*when gumba collides with pathNode*/
	if(other.tag == "pathNode")
	{
		print("instruction from enemyGumba.js: " + gumbaState);
		var linkToPathNode = other.GetComponent(pathNode).pathInstruction;
		print("assign property: " + other.GetComponent(pathNode).pathInstruction + " to variable getPathNodeInstruction = " + linkToPathNode);
		print("getPathNodeInstruction is now: " + linkToPathNode);
		print("now change the current gumbaState:" + gumbaState + " to " + linkToPathNode);
/*
		var tempVar = getPathNodeInstruction;
		print(tempVar);
*/
		
		//gumbaState = linkToPathNode;
		
	}
}

As expected, everything works fine:
1019841--37784--$errConsole.png

Until I uncomment: gumbaState = linkToPathNode;

I get this error:

Assets/2D Mario Assets/Scripts/enemyGumba.js(172,30): BCE0022: Cannot convert 'PathInstruction' to 'GumbaState'.

I was hoping someone can help me figure this out…this is from the WalkerBoyStudio tutorial. I know they’re using an older version of Unity for the tutorials I’ve no idea if this is an issue with newer versions; having the ability to assign a property from an array to another…I don’t think that’s the case, but I don’t know where to start with this

All help/comment is greatly appreciated,
scr33ner

An enum of type PathInstruction is not the same thing as an enum of type GumbaState therefore you cannot directly assign them like this you need some kind of method to convert between the two. As you’re the one who defined the enum, you’re the one who’s gotta map between one and another.

read on here for more

Thanks for the insight BPPHarv, like I said I got these scripts from this video tutorial.

Somehow they were able to get it to work (without converting the enum type to another enum type), but I couldn’t. I have in the past a bit careless with typos taking up days to figure out it was the auto-complete feature that was messing with my code. So with this, I was a bit more methodical made sure I was getting the right data; which I am.

So with newer versions at least with 3.5.5, will I need to convert the enum type to another enum type even with UnityScript?

Actually i just figured out a way easier way of doing this that will make sense to you hopefully.

on the enemyGoombaScript.js you first create a var

var getPathInstruction : int;

function OnTriggerEnter ( other : Collider )
{
if ( other.tag == “pathNode”)
{

var linkToPathNode = other.GetComponent(pathNode);
getPathInstruction = linkToPathNode.pathInstruction;
enemyState = getPathInstruction;

it works great hope it helps you like it did me.

Works apsolutly great !! thanks extremevertigo … btw i heave same idea but i want passing strings exepts int … but anyway thank u :slight_smile: