Imaginary Booleans

hello again darlings, its me freakfish! and i’m back with yet another crazy illogical error.

Assets/Scripts/Characters/CowControl/CowControl.js(21,67): BCE0051: Operator ‘<=’ cannot be used with a left hand side of type ‘boolean’ and a right hand side of type ‘float’.

this is utter bollocks. why you may be wondering? well, none of the variables being used are booleans. they are ALL floats which is rather confusing. here is the script thats throwing up the error:

var samepos = 0;

function SamePositions ()
{
	if (samepos == 0)
	{
		samepos = 1;
		CowMove.move = -0.125;
		CowMove.moveup = 1.5;
		yield WaitForSeconds (1.5);
		CowMove.move = -0.5;
		CowMove.moveup = -0.5;
		samepos = 0;
	}
}

function Update () 
{
	if (BeamTexture.on == 1)
	{
		if (UFOcontrolBox.ufoxpos -0.5 <= CowMove.cowxpos <= UFOcontrolBox.ufoxpos + 0.5) // this is the errored line
		{
			SamePositions ();
		}
	}

	else
	{
		CowMove.move = -0.5;
		CowMove.moveup = -0.5;
	}
}

just so nobody gets confused (mainly me) here are the lines where the variables in the other scripts are being declared:

From CowMove;

static var move = -0.5;
static var moveup = -1;
static var cowxpos : float;
static var cowypos : float;

function Update () 
{ 

	cowxpos = transform.position.x; 
	cowypos = transform.position.y;
...

From UFOcontrolBox;

static var ufoxpos : float; 

function Start(){ 
    ufoxpos = transform.position.x; 
} 

function Update () 
{ 
   ufoxpos = transform.position.x;

so please help people! D: the computer is telling me i’m wrong when logic dictates i’m right! tell me whats going onnnn D:

The problem is that the code is evaluating one side of the <= statement first (which evaluates to a bool) and then tries to compare that bool to see if it is <= to your other value.

Try changing this code

if (UFOcontrolBox.ufoxpos -0.5 <= CowMove.cowxpos <= UFOcontrolBox.ufoxpos + 0.5)

to this

if (UFOcontrolBox.ufoxpos -0.5 <= CowMove.cowxpos  CowMove.cowxpos <= UFOcontrolBox.ufoxpos + 0.5)

Actually, logic is exactly why it’s failing.

if (UFOcontrolBox.ufoxpos -0.5 <= CowMove.cowxpos <= UFOcontrolBox.ufoxpos + 0.5)

Use “” in there as necessary to break that up into blocks where only two items are getting compared at once, otherwise the last operation does have to be a boolean just as the error says. (Although if you did that, only “==” or “!=” would be appropriate.)

–Eric

thanks for the replies, its working now! :smile: