x


Why is there an unexpected token error?

I am working on creating a respawn script in Javascript and I am getting three "BCE0043 Unexpected token: .." errors when I try to run the program. They are on lines 7-9, all three of the variables in the Start function. Here is my code:

#pragma strict

var Position = {};

function Start () {

    var Position.startX = gameObject.transform.position.x;
    var Position.startY = gameObject.transform.position.y;
    var Position.startZ = gameObject.transform.position.z;

}

function Update () {
}

function OnTriggerEnter (other : Collider) {

    if (other.name == "Player"){

        other.transform.position = Vector3(Position.startX, Position.startY, Position.startZ);

    }
}

Any help would be greatly appreciated. Thanks in advance.

more ▼

asked Apr 04 '12 at 12:19 AM

nikemikey3 gravatar image

nikemikey3
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Not quite sure why you're trying to use a hashtable for that; just use a Vector3.

private var startPosition : Vector3;

function Start () {
    startPosition = transform.position;
}

function OnTriggerEnter (other : Collider) {
    if (other.name == "Player") {
        other.transform.position = startPosition;
    }
}
more ▼

answered Apr 04 '12 at 12:51 AM

Eric5h5 gravatar image

Eric5h5
81.5k 42 133 529

(comments are locked)
10|3000 characters needed characters left

Actually, nevermind, I completely changed my code to work in Vector3 correctly. Here it is if this helps anyone else: #pragma strict

var playerPosition : Vector3;

function Start () {

    playerPosition[0] = gameObject.Find("Player").transform.position.x;
    playerPosition[1] = gameObject.Find("Player").transform.position.y;
    playerPosition[2] = gameObject.Find("Player").transform.position.z;

}

function Update () {
}

function OnTriggerEnter (other : Collider) {

    if (other.name == "Player"){

        other.transform.position = playerPosition;

    }
}
more ▼

answered Apr 04 '12 at 12:59 AM

nikemikey3 gravatar image

nikemikey3
1 1 1 1

Take a look at my answer; you can just assign a Vector3, you don't need to do x, y, and z separately.

Apr 04 '12 at 01:47 AM Eric5h5

Indeed, you don't have to make manually a copy of the Vector3 because it is not a reference-type but a value-type. Thus assignation always makes a copy.

Apr 04 '12 at 07:05 AM Kryptos
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3568
x35
x10

asked: Apr 04 '12 at 12:19 AM

Seen: 1293 times

Last Updated: Apr 04 '12 at 07:05 AM