Wednesday, 11 September 2013

Javascript is Ugly, Ugly

So I'm working on a full-page Piggy Petter that will have a little more game to it - although no more game than Candy Box or Cookie Clicker.  But let me tell you something, Javascript is a terrible thing to code in.

You leave a semi-colon out in the middle of some code, or put a semi-colon in, or put brackets beside a function name when you aren't supposed to, and it responds by simply not executing any of the code at all.  I can't find any reasonable way to debug.  Basically I put in alerts for nearly every function saying that the function has been executed and then build new functions through tiny little baby steps, adding one line of code at a time and test running it with each line - often adding more extraneous alerts to let me see if it got to the line where it is actually supposed to do something but where it currently doesn't do anything.

I'd like to thank random internet tutorials for turning me on to Notepad++ which is significantly better than notepad for writing html.

Anyway, I currently have a piggy who will wander back and forth inside a prescribed box and will stop in his tracks to respond happily whenever you pet him.  That's probably four or five hours of work and it's probably coded in a terrible way that: 1) runs inefficiently; and 2) won't allow me to expand in the way I want.  As I alluded to before I also have all my piggy graphics on white rather than transparent backgrounds so I can't put in a nice looking background.  I'm not even sure javascript is a good idea, and it's possible I should be doing something completely different, but it seems like that's the thing that people use.

Well, I've put up the scripts and images on my Google Drive so you can put them up on whatever page you'd like, if you'd like.  I also put up an instructions page.

1 comment:

  1. An easy way to debug browser javascript is to use Chrome's developer tools ( Also, console.log() is typically a lot easier and better to use than alert().