You are not allowed to call this function when declaring a variable.

Hi everybody,
I followed what was written by “simple” in this post: Dynamically Changing the Character Motor Script - Unity Answers

particularly, here is my code:

function Start () {
	gameObject.GetComponent(CharacterMotor).movement.maxForwardSpeed = 10.0f;
}

but I get the following error by unity: UnityException: You are not allowed to call this function when declaring a variable.
Move it to the line after without a variable declaration.
If you are using C# don’t use this function in the constructor or field initializers, Instead move initialization to the Awake or Start function.
UnityEngine.Component.get_gameObject ()

what’s wrong?

is this a js or C# script?

if it’s C#, do this

((CharacterMotor)gameObject.GetComponent<CharacterMotor>()).movement.maxForwardSpeed = 10.0f;

if js

((CharacterMotor)gameObject.GetComponent("CharacterMotor")).movement.maxForwardSpeed = 10.0f;

if I put the quotes I get this error: ‘movement’ is not a member of ‘UnityEngine.Component’
so I removed the quotes, closed Unity3d and reopened it. now it works.