Thursday, March 29, 2012

Learn C++

Hello to the endless void that is my blog :D

Just a quick update. I did pass Avernum which was the goal of creating this blog in the first place, but I failed to update the blog. I took all kinds of pictures too, however when your computer crashes and you lose all your pictures then it's a bit hard to redo it all. So it's a win for me and a loss for my blog.

Once again I am going to treat this blog as my own personal/public diary. This time my goal is a bit harder than passing a game. My goal is to learn C++. The reason for this is that it's been a dream of mine since I was a kid. About a month and a half ago I took a long look at what I've done in the past 10 years and it made me think of what I could have done in those 10 years. While those years weren't exactly wasted, there was so much more I could have done and wanted to do. So now it's time to give myself a 10 year goal of learning C++ and make a game or two, hopefully more than two in ten years time, but I'll keep my expectations low.

To accomplish this goal I have bought a few books, bug a couple of my (mostly just one) programmer friends and found some great sites on the internet. I want to thank Jay Barnson of Rampant Coyote for blogging about all of his experiences in the game development world and for helping me out with the most basic of C++ code. Jay is a really nice guy who goes out of his way to help people and makes some damn fine games in the process. If you've never heard of him then maybe you've heard of Twisted Metal. He worked on that series and blogs frequently about the good old days which are always a good read.

His latest game, Frayed Knights, is superb. I was lucky enough to beta test the game and loved every minute of it. If you've never heard of it, it's an RPG with turnbased combat. The writing reminds me of Terry Pratchet. Not quite so demented at times, but it's pretty darn close. I've played so many games that I hardly ever have any game that actually makes me laugh out loud. This one did. I highly recommend anyone who reads this to give the demo a try. If you like old school RPGs then more than likely you will love this one, unless you're one of those people who has to have everything so damn dramatic all the time. Then you probably won't get the humor. If I had to compare the game to any others it would be like Quest for Glory mixed in with Wizardry.

Enough of the background, let's get to what I've actually learned in a month and a half. We'll I've gone from knowing absolutely nothing about C++ to understanding a few key concepts. I've been using a mix of books, help from Jay and youtube videos. One in particular, antiRTFM. His videos are excellent. He goes very slowly over every new concept learned and gives many examples of what new function does. I've been using his videos (and Jay's help) more and more.

So here's my first program:

#include <iostream>

using namespace std;

int main()
       cout << "Hello World!" << endl;
      return 0;

That little program is the usual first program. It displays "Hello World" on the screen.

In that program you have a few key concepts I needed to learn.
First are headers.

Headers are what is loaded before the program runs. Basically in the C++ libraries there are all kinds of commands/info you can use that has already been created by other programmers, but you need to tell the program you will be using them before you can use them.

main() - Every program needs a main function. Without it your program won't run.

{} block of code - A block is anything between those curly braces {} Later on I learned about nesting and scopes, but for now just think of that as an opening and closing of a letter. You need "Dear ________," and "Sincerely," in a letter. Same thing in C++. You need a { and a }.

cout - cout is console output. Everything in between the " " will be displayed on the screen. It doesn't matter what it is as long as it's between " ".

endl - end of line. I just think of endl as the return button. There is also /n which will also create a new line, but most of the books and videos I see use endl, so I'll use it. Also there is a difference between the two, but right now it's not that important for me to know the difference. Later on with more complex code, I'm sure I'll need to review when to use /n and endl.

; - That semicolon goes on the end of most lines of code in your program. Certain lines of code don't use it, but from my experience most of them do. Example: For (;;) loop doesn't use a semicolon at the end. A cout statement needs it.

<< and >> - I don't remember the name to those, but I think of them as a funnel. Anything on the open end gets funneled into the small end.

I'll end this blog entry here for now. I have learned a lot more than just those commands, but I'll need to review the actual wording and what they do before I blog about them. Like that for loop has many conditions within (), but while I know what they are, I don't remember the actual wording for them.

Hopefully in ten years I can look back at this and think what a newb I was. I would love to have that feeling.

Anyway, have a great day to the few people/bots who came to my blog by accident.

No comments:

Post a Comment