More Coding!

In today’s lesson we were re-introduced to two new errors within coding. Syntax and semantic errors. 1 of the errors was very easy to spot because it was just messed up brackets. Instead of using proper brackets the code used the square bracket []. The other error (Semantic) was not so easy. The semantic error was the more than symbol. The line of code was  if (toTarget.magnitude > range) {  This error is because of the more than symbol. The line of code is basically saying that the space mine will chase the spaceship when it is out of its range (5 m) but when the spaceship is within 5 m of the space mine it wont chase the spaceship. This needed to be changed so the line of code looked like this

(toTarget.magnitude > range) { This line of code is saying that when the spaceship is within 5 m of the spacemine it will chase it. This means when it is out of range it wont. This means if there are multiple spacemines they will only attack the spaceship when in range reducing lag.

This is what the code looks like Spacemine code

I can use this code in many different games like the pachinko game and the Ball roll game. I can use the code to do things like open doors or for the pachinko game make the balls have an effect before the pachinko ball touches it.

 

Leave a comment