Operator '-' cannot be used with a left hand side of type 'Object' and a right hand s

I am finished with my game for the Android. However, I cannot figure out how to keep this error from popping up so I can test my game.
BCE0051: Operator ‘-’ cannot be used with a left hand side of type ‘Object’ and a right hand side of type ‘float’.

The error starts in the function Updatemessage().

private var lowFPS = 15.0;
private var highFPS = 35.0;

private var skipChangesTimeout = 1.0;
private var nextTerrainChange = 0;

function Start()
{
	if( !fpsCounter || !terrain ) {
		Debug.LogWarning("Some of performance objects are not set up");
		enabled = false;
		return;
	}
	
	origDetailDist = terrain.detailObjectDistance;
	origSplatDist = terrain.basemapDistance;
	origTreeDist = terrain.treeDistance;
	origMaxLOD = terrain.heightmapMaximumLOD;
	skipChangesTimeout = 0.0;
	
	var distances : float[] = new float[32];
	distances[16] = Camera.main.farClipPlane;
	Camera.main.layerCullDistances = distances;
}

function Update ()
{
	if( !fpsCounter || !terrain )
		return;
		
	if( !doneNotes  !Application.isEditor )
	{
		var gfxCard = SystemInfo.graphicsDeviceName.ToLower();
		var gfxVendor = SystemInfo.graphicsDeviceVendor.ToLower();
		if( gfxVendor.Contains("intel") )
		{
			// on pre-GMA950, increase fog and reduce far plane by 4x :)
			softVegetationOff = true;
			QualitySettings.softVegetation = false;
			AddMessage( "Note: turning off soft vegetation (Intel video card detected)" );
		}
		else if( gfxVendor == "sis" )
		{
			softVegetationOff = true;
			QualitySettings.softVegetation = false;
			AddMessage( "Note: turning off soft vegetation (SIS video card detected)" );
		}
		else if( gfxCard.Contains("geforce")  (gfxCard.Contains("5200") || gfxCard.Contains("5500") || gfxCard.Contains("6100")) )
		{
			// on slow/old geforce cards, increase fog and reduce far plane by 2x
			ReduceDrawDistance( 2.0, "Note: reducing draw distance (slow GeForce card detected)" );
			
			softVegetationOff = true;
			QualitySettings.softVegetation = false;
			AddMessage( "Note: turning off soft vegetation (slow GeForce card detected)" );
		}
		else
		{
			// on other old cards, increase fog and reduce far plane by 2x
//			if( hwWater == IslandWater.WaterMode.Simple )
//			{
//				ReduceDrawDistance( 2.0, "Note: reducing draw distance (old video card detected)" );
//			}
		}
		
		skipChangesTimeout = 0.0;
		doneNotes = true;
	}
	
	DoTweaks();
	
	UpdateMessages();
}

function ReduceDrawDistance( factor : float, message : String )
{
	AddMessage( message );
//	RenderSettings.fogDensity *= factor;
//	Camera.main.farClipPlane /= factor;
	var distances : float[] = Camera.main.layerCullDistances;
	for(var i : int = 0; i < distances.Length; i++)
		distances[i] /= factor;
	Camera.main.layerCullDistances = distances;
}

function OnDisable()
{
	QualitySettings.softVegetation = true;
}

function DoTweaks()
{
	if( !fpsCounter.HasFPS() )
		return; // enough time did not pass yet to get decent FPS count
	
	var fps : float  = fpsCounter.GetFPS();
	
	// don't do too many adjustments at time... allow one per
	// FPS update interval
	skipChangesTimeout -= Time.deltaTime;
	if( skipChangesTimeout < 0.0 )
		skipChangesTimeout = 0.0;
	if( skipChangesTimeout > 0.0 )
		return;
	
	// terrain tweaks
	if( fps > 25.0 )
	{
		// bump up!
		++nextTerrainChange;
		if( nextTerrainChange >= 4 )
			nextTerrainChange = 0;
			
		if( nextTerrainChange == 0  terrain.detailObjectDistance < origDetailDist )
		{
			terrain.detailObjectDistance *= 2.0;
			if( !softVegetationOff )
				QualitySettings.softVegetation = true;
			AddMessage( "Framerate ok, increasing vegetation detail" );
			return;
		}
		if( nextTerrainChange == 1  !splatmapsOff  terrain.basemapDistance < origSplatDist )
		{
			terrain.basemapDistance *= 2.0;
			AddMessage( "Framerate ok, increasing terrain texture detail" );
			return;
		}
		if( nextTerrainChange == 2  terrain.treeDistance < origTreeDist )
		{
			terrain.treeDistance *= 2.0;
			AddMessage( "Framerate ok, increasing tree draw distance" );
			return;
		}
	}
	if( fps < lowFPS )
	{
		// lower it
		++nextTerrainChange;
		if( nextTerrainChange >= 4 ) {
			nextTerrainChange = 0;
			lowFPS = 10.0; // ok, this won't be fast...
		}
			
		if( nextTerrainChange == 0  terrain.detailObjectDistance >= origDetailDist / 16.0 ) {
			terrain.detailObjectDistance *= 0.5;
			QualitySettings.softVegetation = false;
			AddMessage( "Framerate low, reducing vegetation detail" );
			return;
		}
		if( nextTerrainChange == 1  !splatmapsOff  terrain.basemapDistance >= origSplatDist / 16.0 )
		{
			terrain.basemapDistance *= 0.5;
			AddMessage( "Framerate low, reducing terrain texture detail" );
			return;
		}
		if( nextTerrainChange == 2  terrain.treeDistance >= origTreeDist / 16.0 )
		{
			terrain.treeDistance *= 0.5;
			AddMessage( "Framerate low, reducing tree draw distance" );
			return;
		}
	}
	if(fps < 20)
	{
		if(QualitySettings.currentLevel > QualityLevel.Fastest)
			QualitySettings.DecreaseLevel();
	}
	else if(fps > highFPS)
	{
		if(QualitySettings.currentLevel < QualityLevel.Fantastic)
			QualitySettings.IncreaseLevel();
	}
	
	if(QualitySettings.currentLevel < QualityLevel.Good)
	{
		var sh : Shader = Shader.Find("VertexLit");
		var bumpedObjects : GameObject[] = GameObject.FindGameObjectsWithTag("Bumped");
		for(var i : int = 0; i < bumpedObjects.length; i++)
		{
			bumpedObjects[i].renderer.material.shader = sh;
		}
	}
}

function AddMessage( t : String )
{
	messages.Add( t );
	times.Add( messageTime );
	lastTime = scrollTime;
	skipChangesTimeout = fpsCounter.updateInterval * 3.0;
}

function UpdateMessages()
{
	var dt = Time.deltaTime;
	for( var t in times )
		t -= dt;
	while( times.length > 0  times[0] < 0.0 ) {
		times.Shift();
		messages.Shift();	
	}
	lastTime -= dt;
	if( lastTime < 0.0 )
		lastTime = 0.0;
}

function OnGUI()
{
	var height = 15;
	var n : int = messages.length;
	var rc = Rect( 2, Screen.height - 2 - n * height + (lastTime/scrollTime*height), 600, 20 );
	for( var i = 0; i < n; ++i )
	{
		var text : String = messages[i];
		var time : float = times[i];
		var alpha = time / messageTime;
		if( alpha < 0.2 )
			GUI.color.a = alpha / 0.2;
		else if( alpha > 0.9 )
			GUI.color.a = 1.0 - (alpha-0.9) / (1-0.9);
		else
			GUI.color.a = 1.0;
		
		GUI.Label( rc, text );
		rc.y += height;
	}
}

That error means that you are trying to subtract a float from an Object. Since an Object could be anything, not necessarily a number, this fails. There are two subtractions in UpdateMessage, so either times or lastTime is not clearly defined as a list of numbers / number. In fact, I don’t see those variables defined at all - are you missing part of the file?

Something that’s useful to prevent this situation, and a number of other errors - make your variables typed, even the ones where they’re assigned immediately. It’s better practice, necessary if you go to C#, and may be necessary to run on iOS (can’t remember if that’s still the case).

Thanks. I will do that. Also, I only have two errors and it is in the UpdateMessage function. Also, I will go to C#.

Variables are always statically typed as long as you at least supply a value. Things like “var foo;” should be avoided, but “var foo = Vector2.one;” is fine. You can do “var foo : Vector2 = Vector2.one;” but it’s not actually necessary anywhere, iOS included, since foo is already defined as a Vector2 because Vector2.one is (obviously) a Vector2. That’s called type inference, which also works in C#.

–Eric

Thanks Eric