[SOLVED] Uncaught SyntaxError: Unexpected token 'this'

Here is the link to the game:PlayCanvas | HTML5 Game Engine
Here is the link to the game editor: PlayCanvas | HTML5 Game Engine
Here is the link to the script editor:PlayCanvas | HTML5 Game Engine
this line of code is the problem: if (this.time this.spawnNext) {
I’m trying to randomize the spawn point of the enemy’s ship, but it says that the token ‘this’ is unexpected.
Can you help?

Hi @Bradley_Pelletier!

image

Without checking your logic, I think it should look like below.

// if 1 second has passed
if (this.time >= this.spawnNext) {
    // your other code
}

I replaced the code and it messed everything up, It did not work, is there something wrong with the script?

// Scripting | Learn PlayCanvas

I just fixed a mistake in my example above.

Ok, so nothing changed, but I might have placed it incorrectly too. Is it supposed to look like this?
Screenshot 2022-12-07 085327

No, you have to remove the wrong line that gives the error.

I don’t understand, can you explain a little better?

Which part you want me to explain better?

Ok, so nothing changed, but I might have placed it incorrectly too. Is it supposed to look like this?
Screenshot 2022-12-07 085327

Reply

AlbertosModerator

1h

No, you have the remove the wrong line that gives the error.

I don’t understand the comment you made “No, you have the remove the wrong line that gives the error.”

Which part of my comment is not clear for you? The ‘remove’ part or the ‘line with the error’ part?

The ‘you have the remove’ part, did you mean have to remove?

Sorry, I don’t understand your point. Do you mean my English is not correct here? (That’s possible because I’m Dutch).

Oh, I did not know that, that’s cool!

Alright, I see my typo now. It should be: “ No, you have to remove the wrong line that gives the error.”

That may be the reason then

I’ll delete the line and try it out. I’ll let you know if it works

So I tried it and it spawned 2 ships. I want it to randomly spawn multiple ships in the game.

Good that the error is solved now. Unfortunately, I don’t have the time to check your logic at the moment. I suggest to open a new topic where you explain your current logic, so someone can help you with it.

Looking at it again, maybe you can try to replace >= of my example code above with ==.