Trouble discerning the problem

I’m new to writing code, but with the help of a few tutorials I have a tolerable understanding of it. That said, the code I have tried to write wont attach to game objects due to compile errors that I don’t understand.
Here is the code

var casttime = 4.0;
var manacost = 25.0;
var projectile : Rigidbody;
var initialSpeed = 35.0;
function StartCastOne()
{
	if (Input.GetKeyDown("1")  mana>manacost)
	{
	yield WaitForSeconds (casttime);
	PreparedSpellOne();
	}
	else return;
}
PreparedSpellOne();
{
	if (Input.GetKeyDown("Fire1"));
	{
	BroadcastMessage ("CastSpellOne")
	}
}
CastSpellOne()
{
// functional portion of spell
var instantiatedProjectile : Rigidbody = Instantiate (projectile,
transform.position, transform.rotation);
instantiatedProjectile.velocity = transform.TransformDirection(
Vector3 (0, 0, initialSpeed));
Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
SendMessageUpwards("ApplyManaLoss", manacost,
SendMessageOptions.DontRequireReceiver);
}

If anybody could tell me what I’m doing wrong, I would be very grateful.

Does
BroadcastMessage (“CastSpellOne”)
need a trailing semi-colon?

Also, I don’t think the “else return;” line is necessary (but I doubt it’s causing the compile error).

Could you possibly post what the compile error message is? Thanks.

you have a colon after your if statement and not on the line within the if statement

var casttime = 4.0;
var manacost = 25.0;
var projectile : Rigidbody;
var initialSpeed = 35.0;
function StartCastOne()
{
	if (Input.GetKeyDown("1")  mana>manacost)
	{
	yield WaitForSeconds (casttime);
	PreparedSpellOne();
	}
	else return;
}
function PreparedSpellOne()
{
	if (Input.GetKeyDown("Fire1"));
	{
	BroadcastMessage ("CastSpellOne");
	}
}
function CastSpellOne()
{
// functional portion of spell
var instantiatedProjectile : Rigidbody = Instantiate (projectile,
transform.position, transform.rotation);
instantiatedProjectile.velocity = transform.TransformDirection(
Vector3 (0, 0, initialSpeed));
Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
SendMessageUpwards("ApplyManaLoss", manacost,
SendMessageOptions.DontRequireReceiver);
}

Made a few corrections but I think you need a Start or Awake function. Also, no need to use SendMessage if the method is part of the same script.

Just a helpful tip for compiler errors: when they pop up on the debugger, double click the error and it will bring up the offending script at the line that is causing the error, making it easier to track them down.

Oh, missed that one. But I don’t think it would cause a compile error, but definitely needs to be fixed. Good eye!

Yes, it could.

It most certainly would.

I agree with waltermana that I think your problem is the semi-colon at the end of your if statement:

if (Input.GetKeyDown("Fire1"));

Remove that semi-colon and see if that doesn’t help.

Oh good stuff. I just did a test and that trailing semi-colon on the “if” condition is definitely a culprit. In UnityScript it causes a compile error. In actual ECMAScript/JavaScript/ActionScript it is valid (albeit pointless) compilable syntax.

EDIT: Also, the variable “mana” in your first “if” condition has not been declared.

Ok, first, thank you all for your help, I was surprised at how prompt a response you all gave.

Now the compile error with that script are fixed, well almost all of them.

As FizixMan pointed out, mana isn’t declared in this function. It’s declared in a function that is parent to this object. How could I call up the mana variable from the parent object?

I’m at work, so what i’m going to tell you could be wrong.

gameObject.parent.getComponen("nameOfTheAttachedScript").variableName

… or something like that.

Just add it as an input parameter to your method:

function StartCastOne(mana)
{
   if (Input.GetKeyDown("1")  mana>manacost) 
   ...
}

Then in your parent/calling object:

theChildObject.StartCastOne(mana);
(or however it is that you're calling it)