Monday, April 16, 2012

Back From the Dead

Hello to all my little bots who thrive within my blog. I've been sick for the past couple of weeks so my blog posts and studies had been put on hold. One word of warning if you ever wish to go to Asia, if you catch a cold it will knock the stuffing out of you. Not sure what it is about here, but every time I get sick it's always for at least a week. More than likely it'll be for a couple of weeks. The darn bug just doesn't want to die. Never had that problem back in the states, but here we have super colds.

Well, enough whining back to C++.

Last post I talked about variables and how to assign them a value. Now we are going to mess around with assigning values to the variables.

#include <iostream>
using namespace std;

int main()
    unsigned int hitPoints = 50;
    cout << "Hit Points: " << hitPoints << endl;
    //altering the value
    hitPoints = hitPoints + 100;
    cout << "Hit Points: " << hitPoints << endl;
    //shorter way to write the above line of code
    hitPoints += 100;
    cout << "Hit Points: " << hitPoints << endl;
    //Increment and Decrement Operators
    short extraLives = 1;
    cout << "Extra Lives: " << extraLives << endl;
    cout << "Extra Lives: " << extraLives << endl;
    cout << "Extra Lives: " << extraLives << endl;
    cout << "Extra Lives: " << extraLives << endl;
    extraLives = 1;
    short bonus = ++extraLives * 5;
    cout << "Extra Lives, Bonus = " << extraLives << ", " << bonus << endl;
    extraLives = 1;
    bonus = extraLives++ * 5;
    cout << "Extra Lives, bonus = " << extraLives << ", " << bonus << endl;

    return EXIT_SUCCESS;

That little piece of code will display this when ran:

Hit Points: 50
Hit Points: 150
Hit Points: 250
Extra Lives: 1
Extra Lives: 2
Extra Lives: 3
Extra Lives: 2
Extra Lives, Bonus = 2, 10
Extra Lives, Bonus = 2, 5

You can alter the value of any variable you entered by simply writing it again and giving it a new value. No need to declare it as a short int or anything. It already knows what it is.

For example: I gave my ficticious character 50 hit points with this:
short hitPoints = 50

I then altered the value with this:
hitPoints = hitPoints + 100
I told it to take the value of hitPoints and add a hundred to it. So now hitPoints is 150.

There is an even simplier way of doing that by using a combined assignment operator. In this case I used the addition operator.
hitPoints += 100

That tells the compiler to add 100 to hitPoints.
You can do this with subtraction and the rest. Here's the list:

+=    adds              example: x += 20;        same as: x = x + 20;
-=    subtracts        example: x -= 20;         same as: x = x - 20;
*=  multiplies       example: x *= 20;         same as: x = x * 20;
/=   divides           example: x /= 20;          same as: x = x / 20;
%= modulus        example: x %= 20;        same as x = x % 20;

Next I used an Increment and decrement operator.



Those add one to the variable. In my code I declared the variable extralives and gave it a value of one. Then I added one to that by using ++hitPoints. So now extraLives had a value of 2. I wrote it two different ways.

++extraLives;  this will add one to extraLives before doing anything else.
extraLives++ this will add it after.

I know it doesn't sound like much of a difference, but if you look at this:

    extraLives = 1;
    short bonus = ++extraLives * 5;
    cout << "Extra Lives, Bonus = " << extraLives << ", " << bonus << endl;
    extraLives = 1;
    bonus = extraLives++ * 5;
    cout << "Extra Lives, bonus = " << extraLives << ", " << bonus << endl;

The first bit displays:

Extra Lives, Bonus = 2, 10

and the second one displays:

Extra Lives, Bonus = 2, 5

The reason for this is that the first bit added the ++ and then multiplied extraLives by 5.

The second line added it after it multiplied it by 5. So that extraLives was 2 in both cases, but the bonus was different.

That'll do it for today. Still feeling a bit sick, but wanted to get back to my blog and coding. I hope my bots and one fan are happy again :D

As always:
Same rat channel.
Same rat time.

Monday, April 2, 2012


Hello to all the little bots that live here in my blog. Today I'll be reviewing variables and data types.

As before, I'm no expert. I'm writing this down here to help me understand what I've learned so far.

So without furthor ado I give you variables:

Variable = A portion of memory that you use to store, retrieve and manipulate data.

Each variable I create has a type which represents what kind of variable is stored. So I know of 12 different types. I'm sure there are more, but these are the ones I know of so far.

Common Types                    Values

short int                                  -32,768   to   32, 767
unsigned short int                  0   to   65,535
int                                           -2,147,483,648   to    2,147,483,647
unsigned int                           0   to  4,294,967,295
long int                                  -2,147,483,648  to  2,147,483,647
unsigned long int                   0  to  4,294,967,295
float                                        3.4E +/- 38 (seven digits)
double                                    1.7E  +/-  308  (15 digits)
long double                            1.2E  +/-  4932 (19 digits)
char                                        256 character values
bool                                        true / false

*The range of values is based on your compiler. I'm using bloodshed dev C++

char is for storing character values, int for integers, float for single-precision floating point numbers, double for double-precision floating point numbers and bool for Boolean values (true/false).

Depending on what you declare is what you can store. Here's an example using all of the types I know of:

#include <iostream>

using namespace std;

int main()
    short int level;
    float nextLevel;
    double distanceToTown;
    char rideHorse;
    bool haveHorse;
    int orcsKilled, orcsUnconscious;
    level = 2;
    nextLevel = 3.5323;
    distanceToTown = 72110.53423;
    rideHorse = 'y';
    haveHorse = true;
    orcsKilled = 3500;
    orcsUnconscious = 5400000;
    cout << "\nLevel = " << level << endl;
    cout << "Experience till next level = " << nextLevel << endl;
    cout << "Distance to the next town = " << distanceToTown << endl;
    cout << "Does the character ride a horse to town?\n" << rideHorse << endl;
    // Don't display boolean values
    cout << "How many orcs has the character killed?\n" << orcsKilled << endl;
    cout << "How many orcs has the character knocked unconsious?\n" << orcsUnconscious << endl;
    int food;
    cout << "How much food do you wish to buy? ";
    cin >> food;
    cout << "You have bought " << food << " units of food." << endl;
    typedef unsigned short int sshort;
    sshort horses = 5;
    cout << "\nYou have " << horses << " horses." << endl;

    return 0;


This little program displays:

Level = 2
Experience till next level = 3.5323
Distance to the next town = 72110.5
Does the character ride a horse to town?
How many orcs has the character killed?
How many orcs has the character knocked unconsious?
How much food do you wish to buy ? (enter any number. I chose 5) 5
You have bought 5 units of food.

You have 5 horses

For Level I used a short integer because the number would not be that high.
For Experience I used a float because I wanted to use a fractional number
Same with distance to town, but used a double instead to create a larger number
I needed a character for Does the character ride a horse to town? so I used char
For how many orcs killed/unconsious I put the integer name on the same line. I could have put many more variable names on that line if I wanted. I don't have to go to a whole new line if I am creating a bunch of the same "types" of variables

A couple of key things to remember about variables:
  • Always declare what type.
  • Use the correct type of variable. Don't try to store a character value (the 256 characters) when declaring it's an integer. 
  • If you need fractional parts then use float or double
  • You can declare the variable many different ways. You can declare it first without any value and later on give it a value.
  • OR better yet, give it a value when you declare it
  • identifier names (the name after you declared what type of variable it is) can be anything you want with a few exceptions.
    • an identifier can only contain numbers, letters and underscores
    • No C++ keywords
    • Can't start with a number
  •  Lastly, = (insert value) declares the value
Naming variables is pretty open, but try to follow a few rules. Be consistant, use descriptive names and follow traditions others have set. They don't become traditions for no reason. The way I'm handling naming is by capatilizing any second word. Some use underscores. For example:
int thisIsTheNameOfMyVariable = 5
int this_is_the_name_of_my_variable = 5

I don't like hitting the underscore. It's a pain :D

I know I could go into really detailed explanation, but it's pretty basic.

Declare, Name, Value
  • Declare your type of variable
  • Name it
  • Give it a value

Basic stuff.

int basicStuff = 5;
double notSoBasic = 5.5554;
char itIsBasic = 'y'; 
long double reallyNotBasic = 5.43432324525;
bool didYouDeclare = true;

All of those followed the rule of declare, name and value.

One last thing that is pretty cool. You can redifine how to declare a type with typedef:

typedef unsigned long ulong;

By using that I no longer have to type in unsigned long before declaring an unsigned long int. I can now just type ulong. Also you can just type short or long for short int or long int no need for typedef with those.

That's it for today. Before I go I would like to recommend again antiRTFM's utube videos and Beginning C++ Game Programming. I'm using both and am learning a lot.

Well, good night to all my little bots that thrive and live within my blog.

Same Rat-Channel.
Same Rat-Time.

Saturday, March 31, 2012


Hello to all the bots that live in my little blog and hello to Petteri my second nonbot to post a comment.

Just a quick recap:

  • I'm learning C++ because of an event that took place in my life which made me look back at the past ten years. That made me think of what I could have done in those ten years.
  • I've been at this for a little over a month.
  • I'm using this blog as a personal/public journal on what I've learned so far. My hope is that friendly netizens will pop in from time to time to offer a word of advice or just shoot the breeze about coding.
  • My ultimate goal is to not give up. This blog worked for helping me to stay focused with finishing a game. I'm hoping it will help keep me on track with learning C++ and in ten years time I can look back at these first blog posts and think what a NOOB I was.
  • Lastly, this blog will help me review what I've learned.

Now onto the source code: Arithmetic

#include <iostream>
using namespace std;

int main()
        cout << "5 + 5 = " << 5 + 5 << endl;
        cout << "5 - 5 = " << 5 - 5 << endl;
        cout << "5 * 5 = " << 5 * 5 << endl;
        cout << "5 / 5 = " << 5 / 5 << endl;

       cout << "5.0 / 6.0 = " << 5.0 / 6.0 << endl;
       cout << "5 / 6 = " << 5 / 6 << endl;

        cout << "5 + 5 * 5 = " << 5 + 5 * 5 << endl;
        cout << "(5+5) * 5 = " << (5 + 5) * 5 << endl;

        cout << "5 % 5 = " << 5 % 5 << endl;

        return 0;

This bit of source code will display:

5 + 5 = 10
5 - 5 = 0
5 * 5 = 25
5 / 5 = 1
5.0 / 6.0 = 0.833333
5 / 6 = 0
5 + 5 * 5 = 30
(5 + 5) * 5 = 50
5 % 5 = 0

First thing to note is that there are no new lines between any of the arithmetic problems even though I put spaces between some of them. Example:

        cout << "5 + 5 = " << 5 + 5 << endl;
        cout << "5 - 5 = " << 5 - 5 << endl;
        cout << "5 * 5 = " << 5 * 5 << endl;
        cout << "5 / 5 = " << 5 / 5 << endl;

       cout << "5.0 / 6.0 = " << 5.0 / 6.0 << endl;

       cout << "5 / 6 = " << 5 / 6 << endl;


5 + 5 = 10
5 - 5 = 0
5 * 5 = 25
5 / 5 = 1
5.0 / 6.0 = 0.833333
5 / 6 = 0

That might not seem like a big deal, but if you don't tell the compiler that you want a space then it will not create any new spaces. One way to put a space between the lines would be:

         cout << "5 / 5 = " << 5 / 5 << "\n" << endl;

This would display:

5 + 5 = 10
5 - 5 = 0
5 * 5 = 25
5 / 5 = 1

5.0 / 6.0 = 0.833333

The reason for this is that \n character.

\n = new line
Couple of things to remember for \n is that it needed to be put between the " ". If you don't then you will get a compiler error. Also, it will go to a new line wherever you put it. For example:

       cout << "5 / 5 \n = " << 5 /5 << "\n" << endl;

      cout << "5.0 / 6.0 = " << 5.0 / 6.0 << endl;


5 / 5
 = 1

5.0 / 6.0 = 0.833333

I created 3 new lines in that one line of code. One after 5/5, another after the sum of 5/5 and another with endl;
It might seem like a no brainier, but it takes a while to get used to. The compiler does not care what you intend to do, it only does exactly what you say to do. I've created a few programs where the text was messed up because I forgot to add \n.

Arithmetic expressions:

The compiler also does not care what you type in between the quotes. I could have typed "This is a sandwich  = " << 5 / 5 << endl; and it would have displayed

This is a sandwich = 1

Now after the quotes I had another funnel << and an arithmetic problem. You just need to type the math problem. You don't need any quotes. As a matter of fact you can't use them. Just type the problem in and the compiler will solve it for you and display it. The arithmetic characters are:

+  add
-  subtract
* multiply
/ divide
% modulus

Using those will express a value. Example: The expression 5 + 5 expresses the value 10.

The operators themselves are simple enough .Nothing surprising there except for %
That's a modulus. A modulus gives you the remainder when dividing two numbers. For example:

5 % 5 has a remainder of 0 so the answer is 0
9 % 5 has a remainder of 4 so the answer is 4

There are all kinds of ways I don't understand the modulus and how to use it so I'm not going to pretend to. I do know that when creating random numbers I need to use it, but random is a whole other type of beast. I'll blog about that in a later blog.

What I found most interesting about how C++ does math problems is that if you do not put a ".0" then it will not return any number after the decimal point. It will just return an integer. You need a .0 to get any kind of floating point. A floating point is a number with a fractional part. More on floats and integers later.

In the last example I am adding and multiplying the same numbers but in different orders. Just remember these order of operations

multiplication, division and modulus have equal precedence. They are evaluated first regardless of their position. In other words, they are evaluated before addition and subtraction.

To get around this you can use parentheses. Example (5 + 5) * 5 equals 50 because you first add 5 and 5. Then multiply it. Without the parenthesis you would multiply 5 and 5 and then add 5 which would be 30.

That does it for today.

Recap of what was learned:
  • \n creates a new line
  • Type the arithmetic problem out without quotes
  • + - * / % are the arithmetic operators you use to get an expression
  • Expression is something that evaluates to a single value.
  • To get a floating point expression you need to add .o to the number
  • Order of operations. * / % expresses before + -
  • Use parenthesis to get lower precedence operators to express a value first. Keep this in mind because it will become very important later on when learning more about C++
To the few netizen travelers and all the little bots that live in the void that is my blog, see you next time.

Same Rat-Time.
Same Rat-Channel


Friday, March 30, 2012

The Basic Commands

Here's more of what I've learned so far. The basic stuff cont (not basic as in BASIC :))

Whitespace - The compiler mostly ignores blank spaces aka whitespace. Whitespace is used mostly for us humans so we can read the code easier.

#include - This is a preprocessor directive. It tells the program what to include in your program. A file that you include in the program is called a header file. Examples of some header files and how to write them:

#include <iostream>
#include <string>
#include <vector>

// commenting - If you want to comment on some piece of code to make it easier for you or others to understand what it does then type // for a comment that is only one line or /* */ for multiple lined comments. Example:

// This is my comment
#include <iostream>

/* This is
my multiple
lined comment.*/

#include <iostream>

Functions - A function is a group of programming code that does some work and can return a value. More on functions later, but for now all you need to know is that you need to have a main() function in every program. Example:

#include <iostream>

using namespace std; 


I'm probably repeating myself but get used to that. You'll be repeating yourself in the code many many many times or at least I am. To really understand anything I have to play around with it. Trying different things and seeing if it works. Now onto more basic things.

cout - I didn't mention before that cout is a string literal which means it's literally the characters between the quotes.

cout is an object from the iostream (header file we included in the first program).

<<  - The name for this is output operator. Like I said before, it takes whatever is on the open ended side and puts it in the closed end side.

If I wasn't using "using namespace std;" then I would have to attach a prefix to the cout string literal. For example without using namespace std;

#include <iostream>

       std::cout << "Prefix example.";
       return 0;

That std is a namespace which tells the compiler where to look for "cout". In this case the compiler looks for "cout" in the standard library. It's like an area code. Without that area code the compiler wouldn't know where to look for cout.

That is where "using namespace std;" comes into play. This little line of code loads the standard library into the program so you don't have to type an area code every time you want to use cout or anything else from the standard library. I'm sure there are reasons to use a prefix with every line of code, but for what I want to accomplish I think for now it would be much easier if I don't have to type that in every time I want to write an object from one of the libraries. I would have to do that with every single object I used. Example:

#include <iostream>

      std::cout << "Another example." << std::endl;
     return 0;

Since both cout and endl are in the standard library I would have to tell the compiler where both of them were.

This of libraries like this:

There's the standard library. Within that is iostream. Within that is cout.

 ; - I mentioned this before, but I'll get more techincal this time around.

All statements must end in a semicolon. cout << "blah blah blah" << endl; is  a statement so it needs a semicolon. Simple as that. Just like most sentences need a period or some other form of closing punctuation.

return 0;

This will be explained more when dealing with functions, but for now just think of this as the off button.

So let's wrap up so I don't keep repeating myself next blog entry.

We've learned about:

functions (tiny bit)
cout (a string literal)
return 0

I apologize in advance if you really are trying to learn something about C++ by reading this. I'm still learning myself and my thought process is all over the place. I'll try to keep things more organized from now on.

Well to all the little bots that live in the void that is my blog, see you next time.
Same rat channel.
Same rat time.....maybe :D

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.

Tuesday, January 25, 2011

Welcome to Avernum

Avernum is an indie rpg made by Spiderweb Software. It's a classic turn-based role-playing game with an open world, many quests, a robust skill system and a choice of four PCs. RPGs of today do not make these types of games anymore.

The story is that your party of four has been banished to the underworld for some unknown crime against the cruel Empire. The underworl, or Avernum, is where the Empire sends all of its dissadents, criminals or just because someone in power didn't like the way you look.

When you first arrive at your knew home you have no idea what is going on or what to do. It's up to you to decide for yourself what actions you want to take.

My dream to be traveling around with three women has come true for Rincewind.
 You start out by choosing four characters and what kinds of skills you want them to have. There are suggested skills for certain character classes like Soldiers have more strength, endurance and are better with multiple weapons. While a sorcerer has very little strength, more intelligence and knows some magic. You don't have to choose a class. You can choose customize if you want and then you can spend the skill points any way you which.

Here we can see all of the different skills and various other information about one of your characters. I have five extra skillpoints I can spend anywhere I want. In addition there are various character traits I can choose from. You have both benificial traits and ones that are not so beneficial. The ones that help you like beastmaster will allow you to summon beasts once per day, but you will get less experience points throughout the game. If you choose a harmful trait then you can receive extra experience points throughout the game. I try to balance it out sometimes. Like choosing the natural mage trait that enables my mage to wear armor and then choosing the brittle bones trait which means I will need to stay out of physical combat. I was going to do that anyways, so why not make have more of an incentive. By doing this I would receive 5% extra expeirence from my adventures, -25% for being a natural mage and +30% for having brittle bones.

Now the story begins:

So this is Avernum and the infamous gate. I have my four party members there are on the screen and the stats and equipment on the right of the screen. At the bottom it tells you game information or dialogue and below that are the tabs for various actions. Starting from the left we have look, mage spells, priest spells, wait a turn, talk, get, combat mode, use a skill, journal, options and help.

This game is easiest when played using a keyboard. The mouse takes too long. You use the numberpad to move around and hotkeys. For example: hit g to "get" items.

Now I go find out what's going on.

I talk to the various people and learn that they are here to "welcome" me to Avernum and provide me with some basic gear so I don't resort to thievery out of desperation. I also learn that they are having problems with bandits, the Nephilim (cat people) and Slithzerikai (lizard men).

So now I leave this safe setting in search of fame, glory and riches in Avernum.

Wednesday, January 19, 2011

My Gaming World

Welcome to my blog. I'm starting this mostly for myself, but if some of you enjoy my posts on games then all the better. I'm hoping that by starting this I will try to finish more of the hundreds of games I have without buying a ton of new ones. There are just too many games being released nowadays that I don't have a chance to finish the ones I have before a new shiny one becomes available. Also, I'm a little tired of all the information I have written down in forums being lost. I would like to have one place where I keep all that information for future reference.

I would like to thank Hedge_Witch, Rampant Coyote and CRPGAddict. They have some of the best blogs I've seen and inspired me to start my own. If you enjoy poetry then I highly recommend you go to Hedge_Witch's Verse Escape. If you enjoy indie games head on over to Rampant Coyote's site and if you enjoy awesome old games then CRPGAddict's site is for you.

As for my blog I will post my progress through a game complete with screenshots and then give a mini-review at the end. I play all kinds of games ranging from FPS to RPG to strategy games. My favorites are RPGs and if you enjoy playing crpgs then I highly recommend you head on over to They have the best news and forums, imo. Although I might be a little biased since I'm a staff member over there.

My first game will be Avernum. Avernum is an RPG made by Jeff Vogel. It takes place on another world where my party of four are banished underground by the ruling government for some unknown crime. So without furthur ado I give you Avernum.