Only in Mobile BCE0005: Unknown identifier

Hello! Thanks for taking a look!

So the unity console spits out error BCE0005: Unknown identifier on every call of x and t2

i have no clue as to why is this is, as the code was running well when testing in desktop mode, i switch to Ios and this.

Any help would be greatly appreciated and an explanation of why this is happening would really help me out.

import UnityEngine.Mathf;

var segements : Transform[]; 
var res : int = 5; 
var string : LineRenderer;
var stringLength : float = 4; 

function Awake () {

	segements[0] = GameObject.FindWithTag ("Player Hand").transform; 
	for (x=1;x<segements.length;x++) {
		var joint  = segements[x].GetComponent ("ConfigurableJoint"); 
		segements[x].position = segements[0].position;
	}
	segements[1].GetComponent ("ConfigurableJoint").connectedBody = segements[0].rigidbody; 
	
	for (x=1;x<segements.length;x++) {
		joint  = segements[x].GetComponent ("ConfigurableJoint");
		segements[x].position = segements[0].position + Vector3(0,joint.linearLimit.limit * x,0);
	}
}

function Update () {
	stringLength += Input.GetAxis ("StringAdjust")*0.2; 
	stringLength = Mathf.Clamp (stringLength,0.5,30); 
	string.SetVertexCount (res); 
	for (var i : float =0;i<res;i++) {
		string.SetPosition (i,CubicBezier (i/(res-1),segements[0].position,segements[1].position,segements[2].position,segements[3].position)); 
	}
	for (x=1;x<segements.length;x++) {
		segements[x].GetComponent ("ConfigurableJoint").linearLimit.limit = stringLength/(segements.length-1); 
	}
}

static function CubicBezier (t : float,p0 : Vector3,p1 : Vector3,p2 : Vector3,p3 : Vector3) {
	t = Clamp01 (t); 
	t2 = 1-t;
	return Pow(t2,3) * p0 + 3 * Pow(t2,2) * t * p1 + 3 * t2 * Pow(t,2) * p2 + Pow(t,3) * p3; 
}

2 Answers

2

Every javascript script in Unity needs to start with:

#pragma strict

This says to the compiler that the JS script you write will have every variable correctly typed and declared. See here. Your variables x and t2 are not declared anywhere, that is, you do not have a declaration for them. If you add:

var x : int;

and

var t2 : float;

to your code in appropriate places you’ll see the error disappears. Never, ever remove the pragma-strict from the code, and instead, fix the errors that occur in your code.

Finally, if you need to ask help about errors in your code, please consider posting the line numbers where the errors occur. The line number is the first of the pair of numbers in parentheses.

Not sure bit i think i just lost my reply so is this is a duplicate then sorry Thanks for the help Graham, for anyone else that my see this, I had to use static var x : int; static var t2: float; but everything is working perfectly now ! I had a read up on #pragma strict i see the error of my ways, Thanks again for the pro tips Graham!

Thanks for the help Graham i owe you one!

Just for anyone else who might see this i had to use

static var x : int;

static var t2: float;

so now its working perfectly!

Also i had i read up on #pragma strict and see the error of my ways, thanks again for the pro tips Graham!