- Home /
Which variable can be implicitly declared?
Hi Guys,
My console shows an warning message, but it was gone after 1st play tried. It was saying my function, could be more implicitly declared.
But I look at my variables, I already implicitly declared them. I don't know what else, it can be implicitly declared.
1) Please help me take a look at it. What variable still need to be implicitly declared?
The warning message:
Assets/_scripts/tower_script.js(18,10): BCW0023:
WARNING: This method could return default value implicitly.
//which is the function getclosestEnemy
Below is my code:
#pragma strict
private var ttag = "enemyAim";
private var target : Transform;
var closestEnemy : Transform = null;
var dist : float;
function Start ()
{
InvokeRepeating("getClosestEnemy", 0 , 1.0);
}
function Update ()
{
}
function getClosestEnemy () : Transform
{
var taggedEnemys = GameObject.FindGameObjectsWithTag(ttag);
var closestDistSqr = Mathf.Infinity;
print(closestDistSqr);
for (var taggedEnemy : GameObject in taggedEnemys)
{
var dist : float;
var objectPos = taggedEnemy.transform.position;
dist = (objectPos - transform.position).sqrMagnitude;
if (dist < 3.0)
{
if (dist < closestDistSqr)
{
closestEnemy = taggedEnemy.transform;
closestDistSqr = dist;
}
}
}
target = closestEnemy;
}
2) It's weird, when I keep try to play, sometimes, it will show the warning message, and sometimes it don't.
it's hard to repeat to get the warning message. My console's tabs all unselected. What is that happening?
The script is attached to the tower to shoot enemies that are coming out, a tower defense game.
Thanks in advance.
Answer by whydoidoit · Jul 15, 2012 at 08:36 PM
You specify that getClosestEnemy will return a Transform - but then you don't actually return anything... You either need to drop the : Transform or return something.
@whydoidoit, thanks $$anonymous$$ike! it solved the issue! :D