Unit-based movement script returning weird debug errors

I’m attempting to make a grid-based first-person dungeon crawler setup a la Wizardry or Might Magic. I need the player object to move forward 4 units over a given amount of time (probably 1 second) every time the up arrow key is pressed, and it’s returning very weird errors.
If I can get this working for forward movement, rotational movement shouldn’t be too hard.
Walls can be calculated with a child object talking to a global variable in the script, so I’m not too concerned about that.

The isMoving variable is to make sure that the player can’t force the player object to move off the grid. The “Up” button has already been declared in input properties so that isn’t it.

var isMoving = false;
var speed  = 10.0;
function Start () {

}

function Update () {
	if (Input.GetButtonDown("Up")  isMoving == false){
	isMoving = true;
	transform.position = Vector3.Lerp ((transform.position.x, transform.position.y, transform.position.z), (transform.position.x, transform.position.y, transform.position.z + 4), speed * Time.deltaTime);
	isMoving = false;
	}
}

This is returning various errors, including not expecting commas and expecting semicolons at the end of each transform.position.letter statement.
To my understanding, the transform.position.letter statement declares the current position along that axis and is as good as an integer for this sort of thing. The API reference guide seems to think so anyway.

I have also attempted it in a manner suggested for similar problems elsewhere (using variables to declare the vector3):

var isMoving = false;
var speed  = 10.0;
var startPosition : Vector3(transform.position.x, transform.position.y, transform.position.z); 
var endPosition : Vector3(transform.position.x, transform.position.y, transform.position.z + 4);

function Start () {

}

function Update () {
	if (Input.GetButtonDown("Up")  isMoving == false){
	isMoving = true;
	transform.position = Vector3.Lerp (startPosition, endPosition, speed * Time.deltaTime);
	isMoving = false;
	}
}

It returns similar errors.
I’m a newbie at coding but this seems like it really should work. Anyone know what’s wrong with it?

Unity version 3.53f3

Your syntax is wrong. Right way to define a vector var would be

var VectorVar : Vector3 = Vector3(0,1,2);

In your first script you also need Vector3 before parentheses.
If there is no class in front of them, they act as mathematical operation and comma(,) is not a valid function in math in this case. And Lerp accepts 2 Vector3s so you’d need a class that returns that type either way.

This should go into scripting next time.

Your startPosition and endPosition should be set up in Start. Otherwise the values will be “stuck” with what they were when the script was first attached to an object, since the values in the inspector take precedence over code. You should only define variables outside Start/Awake and nothing more; “real code” that “does stuff” should always be inside functions. In any case there doesn’t seem to be a reason to have startPosition and endPosition as public variables. Also there’s no reason to separate out transform.position.x etc. in this case.

private var startPosition : Vector3;
private var endPosition : Vector3;

function Start () {
    startPosition = transform.position;
    endPosition = transform.position + Vector3.right * 4;
}

Finally, your Update function won’t work. GetButtonDown is only true for one frame, and Lerp is not a function that “does stuff over time”. It’s a very simple math function that returns a value once, immediately. The simplest thing would be to use a coroutine for moving the object; something like this. See here for more about Lerp.

–Eric