Monday, September 29, 2008

Switch Statements

So its been a while since my last blog entry. Sorry about that, as usually happens, life sucks. So we move on.

Last time we talked about If Statements and nested If Statements. As you could tell, nesting if's can get really confusing. Switch statements can help a lot with that.

Here is the syntax for a Switch statment:

switch (selection variable)
{
case label1: statement1;
case label2: statement2;
case labelx: statementx;
default: default statement;
}

The selection variable may be either a number, a string, or a variable that is equal to either a number or string. The switch statement then selects the correct case where the label = the selection variable. If no case is found that matches, then the default is used.

Here is an example

switch (%spellnumber)
{
case 1: %spellname = "Fire Ball";
case 2: %spellname = "Poison Cloud";
case 3: %spellname = "Sleep";
case default: %spellname = "Magic Missle";
}

The equivalent if statement would look like this:

if %spellnumber == 1
%spellname = "Fire Ball";
elseif %spellnumber == 2
%spellname = "Poison Cloud";
elseif %spellnumber == 3
%spellname = "Sleep";
else
%spellname = "Magic Missle";

As you can see, for ever 1 line of a switch statement, the if statement requires 2. It might not seem that bad with only 4 selections to choose from, but imagine if there were 50, or 100! And remember, we are looking to make a game here. The more choices for the player the more likely the are to keep playing.

Saturday, September 13, 2008

Why this blog? (Sorta off topic)

So I was recently asked: "Why are you making this blog? Are you going to make money at it?"

Well no, I do not plan on making money at it. I don't even know if anything will ever come of this blog. So far nobody has gone out of their way to comment on it beyond the above question. But that is ok, it isn't really for them, this blog is for me.

So, anyways, here is the "Why" behind this blog:

Once, I had a dream. In that dream the Navy would teach me all about computers and technology. Yeah, that didn't happen. Then I thought I would go to college to learn about computers (Dot Com crash, anyone?). So yeah, that didn't happen either.

Every few years it seems I would make a good start on getting my programming up to speed, but then something would happen that would make me lose heart. Or I would get to busy. Or the kids would need me. Or my software would be out of date.

Too many excuses. Not enough reasons. We've all been there.

So here I am. Writing this blog. I've got the tools to program (finally). I've been building the knowledge for years. I just need to apply it and get it to stick in my head. I once read that the best way to learn a topic yourself is to teach it to someone else.

And so: This Blog!

This blog is about forgotten dreams, lost years, and hopes that are still alive. It is about making me listen to myself. "Damn the torpedoes, full speed ahead!" comes to mind. Or maybe "STFU if you don't wanna read my blog, you don't have to."

But yeah, not gonna make any money on it. Never planned to, never hope to. But thats ok, just writing the blog is its own reward.

And besides: if someone else learns something from it, bonus!

Tuesday, September 2, 2008

Things to remember

While working on determining the fate of Wally and Ralph I have stumbled on a few things that are important to remember. I've gone over them in the last week, but I figure it doesn't hurt to share them again (plus it will help me remember):

Arrays:

$char1[1] is a valid array, $char1(1) is not. (notice [] vs. () )
Return statements that do not pass a value do not need ()
Pay attention to boolean arguements || means OR in torque script OR means nothing

Work on Wally and Ralph continues. I have learned a lot and am working on making the script more efficient. While it runs almost instantaneously the way it is, you can imagine how much it would slow TGE down if it were being run for 1000 characters instead of just 2.