Strict JS variable errors

I’ve read some stuff off the forums about how Unity on the iPhone needs strict JS coding, but I’m having a hard time figuring out how to achieve this. My code in Unity works great, but when I bring it to the iPhone, I get around 20 errors (with different variables) along the lines of

Assets/scripts/collideTimer.js(7,40): BCE0019: 'collideTime' is not a member of 'UnityEngine.Component'

Here’s an example of one of the lines it’s pointing to:

#pragma strict

var target : Transform;

function Update () {
	script = target.GetComponent( "carController" );
	var collideTime : int = script.collideTime;    // <--- This line is causing problems
	
	gameObject.transform.guiText.text = "Collide Time: " + collideTime.ToString();
}

From my carController script, the line that calls the variable is this:

var collideTime : int = 0;

I have a bunch of errors that are exactly the same problem, it’s happening when I’m calling a script from another game object and trying to use a variable from it.

What can I do to avoid this error? Is there a good resource for strict JS for Unity iPhone?

collideTime is no int
As such you can not just assign it to an in without casting it first through (xxxx as int)

UnityScript on the iphone has none of its common automatisms.

var script = target.GetComponent("carController") as carController;

seems to solve the problem, and you can even take out the

: int

in

var collideTime : int = script.collideTime;

which leaves

var collideTime = script.collideTime;

Why is that? It looks pretty clear to me that we told it to be one, but I don’t have your programming knowledge by a long shot. 8)

You are right, sorry, my error.
Had the regular time values of Unity which are all non-int in my mind when answering not a specific one you created.

and yes you are right, its the casting because otherwise script is not a CarComponent and it fails because the field you try to use does not even exist.

Thanks Jessy! That worked great. I went through and got all my errors fixed.

Dreamora, you’re right. collideTime shouldn’t be an int, and I’m going to fix that as soon as I get a chance, as what I’m using it for is inconsistent between platforms. Right now it’s just an int that’s incremented on every Update() if the car is colliding with something - not a great way to get actual time.