Operator '-' cannot be used with a left hand side of type 'Object' ???????

I am having problems with my code it is giving me this error?

Assets/Main Scripts/GameMechanics/Achievements/AchievementManagerScript.js(42,64): BCE0051: Operator ‘-’ cannot be used with a left hand side of type ‘int’ and a right hand side of type ‘Object’.

Here is My Code!!

#pragma strict
var firstSwingTex:Texture;
private var firstSwingTaken:boolean;
//private var coins:int;
var edgeMargin;

function Start () 
{
   edgeMargin = Screen.width * .01;
}

function PlayerSwung()
{
   if(!firstSwingTaken)
   {
      unlockAchievement(firstSwingTex);
      firstSwingTaken = true;
   }
}

/*function pickedUpCoin()
{
   coins++;
   switch(coins)
   {
      case 1; unlockAchievement(TEXTURENAME);  Break;
      case 5; unlockAchievement(TEXTURENAME);  Break;
      case 10; unlockAchievement(TEXTURENAME); Break;
   }
}*/

function unlockAchievement(achievementTex:Texture)
{
   var go:GameObject = new GameObject("Achievement Object");
   go.transform.position = Vector3(0,0,Time.time);
   go.transform.localScale = Vector3(0,0,0);
   var guitex:GUITexture = go.AddComponent(GUITexture);
   guitex.texture = achievementTex;
   guitex.pixelInset.width = achievementTex.width;
   guitex.pixelInset.height = achievementTex.height;
   guitex.pixelInset.x = Screen.width * 1.1;
   guitex.pixelInset.y = Screen.height - achievementTex.height - edgeMargin;
   var achievementScript:AchievementScript = go.AddComponent(AchievementScript);
   achievementScript.edgeMargin = edgeMargin;   
}

Hopefully Someone Can Solve This!

Cutting / pasting your code into an editor (to get actual line numbers), the problem seems to be here:

guitex.pixelInset.y = Screen.height - achievementTex.height - edgeMargin;

The provided code doesn’t define what data type “edgeMargin” is, but from the error, I assume it’s an object of some type… Which, as the error says, can’t be “subtracted” from an integer. I assume that edgeMargin has some scalar members that you intended to use instead (for instance, something like “edgeMargin.y” or some such…).

Jeff

I have solved the problem it appears that i did not give my ‘var edgeMargin;’ a type so i made it ‘var edgeMargin:float;’ and it works perfectly now. thank you for the support Jeff :slight_smile: