A Problem with argumented exception

So… im having this error… and in the test mode, it does nothing, but once i compile the the executable file, the game crashes because of it

and even worse… i got no idea how to fix it!.. check it out how hairy this problem is:

I Learned through blood and swet that GameObject.Find, will only find active objects, so… this code would never work :

 GameObject.Find ("forcefield").active = true;

since the force field were inactive, the gameobject.find never fond him… and never turn it to active,… i was down to one last resort… i was to assign the forcefield object to a variable, by doing so… evertime i was to refer to this object, i was going to refer to its variable, so i could manipulate it even if it was inactive…

like this

var forcefield : Transform ; (drag the object here)

Update Function () {

if (Input.GetButton ("block") ) {

forcefield.active = true;

}

else {  

forcefield.active = false;

}

}

wel… then i got the argumented exception!.. it says :

You are not allowed to call get_gameObject when declaring a variable.
Move it to the line after without a variable declaration.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
TRACKINGMODE…ctor () (at Assets/TRACKINGMODE.js:3)

so i decided to ignore this exception after all… the test mode works just fine, the force field apears on the right time and desapears as soon as the player let go of the blocking button… so it was all good… then i compiled the executable file… and the game crashed… and the log said something about the object wasn’t loaded yet so i could not refer to it…

so… whats my exit on this one?.. gameobject.find cant find inactives… and i cant use a transform var to drag the inactive object …

what do i doo?

try enabled instead of active

enable the and disable the script that controls it, instead of the actual thing

Is that TrackingMode.js? Because that particular error usually happens when you do something like:

var blah : GameObject = gameObject;

The code you’ve posted shouldn’t be causing that error…

Unless you’ve actually got those parentheses in there. Comments are written with // preceding them -

var t : Transform; // drag object here

Also it’s “function Update() {”, not “Update Function”. I’d suggest going through at least the 3D platform game tutorial (available in the Resources link up top) to get a handle on Unity’s programming language(s).

i tried enabled, got the same error… (but it worked on the test mode just fine)

and i also changed the

var blah = gameObject;

to

var blah : GameObject = gameObject;

again, same error but it worked fine in the test mode…

oh, and yhea about the function Update, i made a mistake when posting an example here, but in my project, it writed correctly

but man, this is too strange… i should not have getting this errors…

one of my scripts (the trackingmode) has this var called “targets” and is a gameObject kind of var… but no object is draged to it in the inspector… this var only becomes active in runtime… when the player shoots a homing misile, it calculates the nearest gameobject with tag and then assign this object to the var “targets”…

so… maybe this is the error… i am refering to a var that is empty , even before some object is assigned to it?.. maybe unity cant handle this kind of thing, at least not in the compiled game …

var blah : GameObject = gameObject; // bad!
var blah : GameObject;
blah = gameObject; // good!

The first line will throw an error.

If you double-click on the error you’re getting it’ll open the script to the line that’s causing it. Post the script that’s causing the error and we can help more better. :slight_smile:

ok, the script is this one

TRACKINGMODE.JS

var mySphere : SphereCollider;
var targets = gameObject;
var misile : Transform;



static private var wasTriggered : boolean;



function Start(){

if (animation.IsPlaying("subweapon2")) {

	
    mySphere = GetComponent(SphereCollider);
		
		
		
}
}

function Update(){
    if(wasTriggered == false)
        mySphere.radius += 1; //tweak to taste
	
	if (wasTriggered) {
	
	if (animation.IsPlaying("subweapon2")) {} else { 
	
	wasTriggered = false;
	
GetComponent("MEGABUSTER").enabled = true;

GetComponent("FIX").enabled = true;

GetComponent("TRACKINGMODE").enabled = false;



}
	
	}
		
}




function OnTriggerEnter(other : Collider){

    if(other.gameObject.tag == "aimable"  wasTriggered == false){
	    mySphere.radius = 0;
        targets = other.gameObject;
        wasTriggered = true;
		
		animation.Stop("subweapon1");
		animation.Play("subweapon2");
		
		var alvo = targets.transform.position;
		

        

        transform.LookAt(Vector3(alvo.x, transform.position.y, alvo.z));
		
		var sub = Instantiate (misile,GameObject.Find("SUBWEAPONPOINT").transform.position,Quaternion.identity);
		
        sub.transform.LookAt (alvo) ;
     
		

		
 
	

		
		
    }
}

i usualy dont coment on my scripts and because of that it sucks to people get what are they for… this one casts a sphere that detects the nearest target to launch a projectile

There it is - var targets = gameObject

You can’t assign properties (a special kind of member) in initialization. You have to separate it -

var targets : GameObject;
targets = gameObject;

As for the “no comments” thing -
Keep your variables clearly named and you’ll hardly have to comment at all (there are still some things that should be commented but it’s much easier to just ‘read’ the code)
‘targets’ should probably be ‘target’, since it’s singular, but other than that your code isn’t too bad to understand.

whoa thanks! really! now it works perfectly!!

in test mode and in compiled mode! you’re the man vicenti!

ah yhea, about this “targets”… well… when i wrote “target” it changed color, so i though it was some comand that i did know about … so i decided to use targets in plural to avoid any errors

yay!.. it works it works!

Glad to be of help. :slight_smile:

‘target’ is a special variable used in custom Inspector functions, so you don’t have to worry about it unless you’re fiddling with that kind of stuff.