Sunday, July 13, 2014

Lessons learned

I've recently been working through the CodeAcademy JavaScript tutorials, so I randomly decided on Friday I would try to build a text based RPG game using the stuff I've been learning. Mainly, I've been learning about functions, arrays, objects, for loops, while loops, etc. I figured what better way to see what I've actually absorbed than to push my skills to the max by building a simple game that leverages these concepts. (If you aren't familiar with an RPG game - it means Role Playing Game. Essentially, my program provides you with a Scenario and then gives you various options. Depending on what option you choose, your game can have different outcomes). 

Here are some things I've learned this weekend:

  1. The internet is such a huge resource when you get stuck! I ran into an issue on Saturday that I worked and worked on, but could not figure out how to solve. I posted my question on Twitter and within 10 minutes had a conversation going with 4-5 other developers and I learned a few possible ways to solve it. The nice thing though, apparently my question wasn't a complete newbie question and actually posed some challenges to think about.
  2. While programming, when working on logic and flow statements, it's IMPERATIVE that you read your code with an empty & fresh mindset with no preconceived notions. If you think you know what the outcome should be, it can make it very difficult to effectively follow along in your code and troubleshoot.

    I'll try to give an example in layman's terms, which is actually the problem mentioned above:

    A user is presented with options 1, 2, 3, and 4 and each option routes to a different scenario. I wanted to ensure they selected one of the four options and didn't try to select 5 for example. My logical flow was:

    if userOption is not equal to (1 OR 2 OR 3 OR 4) then that is a bad result

    I spent at least 30 minutes reviewing through this line of code and trying to figure out why it was not working. And then finally the light bulb went off! My program was checking to see if userOption was not equal to any of those options; so for example, if I selected 3 (which I wanted to give a good result), it still compared it to 1, saw it was not equal to, and returned a bad result.

    The correct logic is .... ("userOption is not equal to 1" AND "userOption is not equal to 2" AND "userOption is not equal to 3" AND "userOption is not equal to 4") then it returns a bad result.

    That may look confusing, but the first one returned a bad result if "ANY" of the four were true (i.e. 3 is not equal to 1 --> true) and the second returned a bad result only if "ALL" of the four were not true.

  3.  I learned how to use the "Inspect Element" to see where I was having issues with my JavaScript. Ok so this wasn't something completely new to me. I had been told about this feature and have used it some to review my HTML. However, after struggling all weekend to figure out which part of my code I broke, it finally hit me Sunday morning to review the "Inspect Element logs" which tell me exactly which line my error was on. This would have saved me a considerable amount of time if I had used it all weekend. Live and learn right?

Well that's about it for this weekend. Stay tuned for my CodeNinja Adventure RPG game! I've finished a lot of the basic flow but still have a lot to build out. I'm hoping to wrap up the game within the next week or so and I'm going to try to embed the code within my blog so you could just click a link and launch the game. 

I definitely feel like my knowledge of JavaScript and troubleshooting errors has come A LONG way this weekend. Overall, I'd consider this weekend a success!! 

No comments:

Post a Comment