Operator '<' (boolean ? decimal)

Hi guys. I have this script, actually made by me:

#pragma strict
public var position: Vector3;
function Start () {

}

function Update () {
var target;
var minx : System.Decimal;
var maxx : System.Decimal;
var minz : System.Decimal;
var maxz : System.Decimal;
var currx : System.Decimal = transform.position.x;
var currz : System.Decimal = transform.position.z;
if(minx < currx < maxx & minz < currz< maxz)
{
print("Successfull");
}
}

And I got this error:
“Operator ‘<’ cannot be used with a left hand side of type ‘boolean’ and a right hand side of type ‘System.Decimal’.”

What have I done wrong ? It’s my only script I need to make to finish my project. Please guys.

You need to revisit your basic algebra. I can’t begin to tell you where that if statement went wrong. There’s a certain grammar to these things.

Welcome to the forum.

This does not work:

minx < currx < maxx

Instead you need to write it like that:

minx < currx && currx < maxx

Please use code tags from now on:

The error disapeared, but now I get 4 errors almost the same , to that line.

Operator ‘<’ cannot be used with a left hand side of type ‘float’ and a right hand side of type ‘Object’.
Operator ‘<’ cannot be used with a left hand side of type ‘Object’ and a right hand side of type ‘float’.
Operator ‘<’ cannot be used with a left hand side of type ‘float’ and a right hand side of type ‘Object’.
Operator ‘<’ cannot be used with a left hand side of type ‘Object’ and a right hand side of type ‘float’.

And, after I put my script on my car, It didn’t show me to modify ‘minx’ / ‘maxx’ etc… This is my script now after some modification:

#pragma strict
public var position: Vector3;
function Start () {

}

function Update () {
var target;
var minx;
var maxx;
var minz;
var maxz;
var currx = transform.position.x;
var currz = transform.position.z;
if(minx < currx && currx < maxx && minz < currz && currz < maxz)
{
print("Successfull");
}
}

Have you set values for minx, max,minz, maxz ?

Why are you using Decimal? Just try to use float instead.

@Dantus
It works with float (doesn’t give any error), but still, I can’t change the minx/maxx/minz/maxz.
This is my script put on my car:

My script now:

#pragma strict
public var position: Vector3;
function Start () {

}

function Update () {
var target;
var minx : float;
var maxx : float;
var minz : float;
var maxz : float;
var currx = transform.position.x;
var currz = transform.position.z;
if(minx < currx && currx < maxx && minz < currz && currz < maxz)
{
print("Successfull");
}
}

Edit: I guess my Position is because of the useless public var I put in the top, I will delete it if this is the problem. But how can I define the others, also the target, if needed.

You have the useless position there. How about moving the variables there that you want to see just like the position?

You can’t write code like “var target;”. You must always define the type, either explicitly, or implicitly by supplying a value.

–Eric

Unity’s inspector will never show you variables that are defined inside of a method. All of your variables right now are defined inside of your Update() method. You have to move them outside of that method before they will show up in the inspector.

Thank you very much guys. I finally made it with “public var minx/maxx/minz/maxz”, and it worked as I wanted.
Really nice help guys, I wish you the best!