Beginning Game Development Path - Need Opinions

Started by
11 comments, last by MichaelRPennington 11 years, 7 months ago

Basic input would be interesting, I was wondering how I should catalog and reference commands...

Should I do a string of if statements, or store them in an array, list or dictionary?

My basic command structure should end up being something simple, such as '[action] [target]' like Attack Goblin, or Open Inventory, or Open Door. This seems simple enough. We can just take the input string and split it by a delimiter, such as a space or '>', so the input could look like 'attack>goblin', and then reference it with the list of commands and functions to call..

Typically this is done by parsing the input string and looking for keywords, such as "attack" which will perhaps fire an attack() method, and the second parameter says "goblin" so the method looks for a goblin near you and throws the dice to get the total damage done. You can get away with splitting the string and feeding the substrings into arrays and methods for simple commands, but once you get to more complicated syntax it gets messy quickly. Perhaps using a scripting language would be worthwhile when you reach that point.

My question is, what method to go about call the functions once the game realizes what command you have given...[/quote]
Scripting languages would solve this, but another method could be a huge switch case associating each main command with its function (or you could create a lookup table mapping command strings to the correct function pointers). There are many ways.

Oof, why does C++ make everything so complicated? Even something as simple as splitting a string is drawn out to an unreasonable extent... It makes me miss Java.[/quote]
Well, how do you think Java does it under the hood? It just hides all that stuff from you, but it doesn't mean it isn't there smile.png And if you are going to be working with strings alot, you may want to download a C++ string utility library (if the standard libraries are not sufficient), or you could write it yourself, so you'd have a little utility library with functions such as splitString(), parseDelimited(), etc...

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Advertisement

Well, I know basic C++, but I just don't know how to apply it to my situation. I'd really like to use C++ rather than Python... Working with Python makes me realize that I'm not a big fan of blank space. I like encapsulation... Give me the good ol' curly brackets any day Posted Image

Basic input would be interesting, I was wondering how I should catalog and reference commands...

Should I do a string of if statements, or store them in an array, list or dictionary?

My basic command structure should end up being something simple, such as '[action] [target]' like Attack Goblin, or Open Inventory, or Open Door. This seems simple enough. We can just take the input string and split it by a delimiter, such as a space or '>', so the input could look like 'attack>goblin', and then reference it with the list of commands and functions to call...

My question is, what method to go about call the functions once the game realizes what command you have given...


Oof, why does C++ make everything so complicated? Even something as simple as splitting a string is drawn out to an unreasonable extent... It makes me miss Java.


The questions you're asking are basic C++. So you don't know basic C++ quite yet! :-)

However, you do show some knowledge and initiative. That's a major ++2 on your chances to succeed. So don't be discouraged. Keep learning the basics. Try, toil and struggle with a game if you must and your mind is set on it. You'll still learn, it will just take a long time to feel successful and recieve any gratification for your efforts. If you're not the type of guy who lets that stop him then go ahead and keep trying to write a game and don't slow down.

To answer your C++ question, if you're using an [action][target] structuring for your command inputs, then you'll want to learn to write your own class. I'll show you what I mean in C++-ish pseudo-code so you still have the challenge of doing it yourself:

[source lang="csharp"] class Command
{
public Command(string action, string target) {
this->action = action;
this->target = target;
}

public string action;
public string target;
};

int Main(string[] args)
{
PrintHelpMenu();

Command cmd = getCmd();

// This is how you use if/else
if (cmd.action == "close")
{
if (cmd.target == "game")
Exit();
else if (cmd.target == "menu")
CloseMenu();
else ;
// whatever...
}

// This is how you use case/switch
if (cmd.action == "open")
{
switch (cmd.target)
{
case "help":
PrintHelpMenu();
break;


case "items"
ShowItems();
break;

// blah, blah, blah... You get it now! smile.png

default:
break;
}
}
return 0x00;
}[/source]

Don't try to compile and run that code, because it's not valid C++. Though it is quite similar in syntax and style. Read it and take the concept it expresses and learn to do such things in C++. Programming, after all, is learning to turn concepts in your head into code! :)
_______________________________________________________________________________
CEO & Lead Developer at ATCWARE™
"Project X-1"; a 100% managed, platform-agnostic game & simulation engine

Please visit our new forums and help us test them and break the ice!
___________________________________________________________________________________
Thanks a lot guys. I'll keep studying up. +1 for both of you :P
Any problem can be fixed, any issue balanced, any design possible; it's a matter of your resolve to make things happen.

Those who say, "It's not possible!" should look at where games started and where games are today. I'm sure they once thought that millions of players playing and interacting at once was not possible, yet we play games that match that description everyday.

Never tell me that something isn't possible; it will only make me more determined to prove you wrong.

This topic is closed to new replies.

Advertisement