Saturday 3 September 2016

Stupid squiggly curly pieces of crap




Right now I have a real issue with the curly bracket {, so much so I am considering asking it to step outside, but GODDAMN IT I don't know which one to ask.

A routine compile on what was an otherwise perfectly operational piece of code before some minor changes has resulted in this:


Errrrrr you what, bruv?



AAAAAAAAAARRRGHHHHHHHH!!!

So I know there is an error. But I don't understand enough about Unity/C# to identify what that is yet. At the bottom of the Unity screen the error log is repeated, but you can see the full message. Which looked like this:



 Ahah! Unexpected symbol '}'. So there must be an extra } somewhere which is mucking up my delicious code.

I searched the code methodically, first with a visual scan, then with a trusty pencil and post it note (my speciality).

Maybe you can spot the error?


This post it note has lines printed on it :D

They all matched up though. Every } had a { preceding it. So where was the unexpected one?

I got some help from Husbandcoder. He spotted it straight away, but still patiently listened as I explained what I had done so far. Explaining things to him was good, because I got to cement what I had just learned in my mind, but it didn't solve the problem!

He pointed something out to me that I am going to find invaluable, as I know in the months and years to come I am going to find many errors! In the error log it actually tells you what line the error occurs on - in this case line 28.

Ahah! I have located the devil!


Ok so cut to line 28 and whooopah right? Hmmmm, no. Line 28 didn't have an extra }, nowhere did, I had already checked that.

So the next nugget of gold from the Husbandcoder was to look at the line of code just before the one that the compiler was saying that the error was on. This is because as the error could well be with what came just before, but the compiler doesn't realise there is an error until it gets to the next piece of code.

So I looked at line 27. Have you spotted it yet?


It's in there somewhere...

It's missing a semi colon! Without it the compiler doesn't know that my print statement is finished and therefore wasn't expecting a } at the start of line 28. That's why it flagged the } as an error.

That's on small ; for man, one giant error for Mandoid.


So I added the pesky little critter and all is well! Sleep tight coderinos!

No comments:

Post a Comment