Step-by-Step Guide to Creating a Text-Based RPG

Page 1 of 2 12 LastLast
  1. #1
    Crumbly, yet Good Reputation: 75
    Eriond's Avatar
    Join Date
    May 2006
    Location
    Montreal
    Posts
    1,798
    Rep Power
    0

    Default Step-by-Step Guide to Creating a Text-Based RPG

    Step-by-Step Guide to Creating a Text-Based RPG
    Part 1

    This is a guide about how to create a text-based RPG using C++ (an actual programming language. no rpg-maker required!). All you need to start is Windows and the free IDE Dev-C++. If you don't have Dev-C++ installed, check out this post, it explains how to install it, step-by-step. http://www.onrpg.com/boards/1215.html

    This is a very good place to start if you want to eventually program in 3D using DirectX or OpenGL, but don't really know a whole lot about programming. I know it sounds less than glamorous to make a text-based game, but to be honest, the difference between a text-based game and a 3D game is just a whole bunch of math; most of the programming fundamentals are the same. So! Let's get started. What you're going to be doing is learning how to write a small program, compile it, and run it in a dos window. First we're going to make a small program called “Hello World”.

    Hello World

    Hello world is the traditional name for the first program a programmer writes in a new language they're trying to learn. Don't ask me why; it's probably some inside joke from like the 70's at IBM .

    So, let's fire up Dev-C++, and create a new project.

    Creating a New Project

    To make a new project, do this: (these steps might not look exactly the same on your computer, I'm not actually using windows in these screenshots )

    Click this button.


    Select console project.


    Name your project, it can be whatever you want,it doesn't matter.


    Create a new folder for your project. Again, it doens't matter where the folder is, for the sake of convenience, I'm creating it in the Dev-C++ folder here.



    Now save the .dev file in the new folder.


    You should get a nice new window with some code in it, essentially the code I'm about to post to you below, but a bit different. Just delete the code they put in there, and paste in the code I'm about to post.

    Oh, just a note about the semi-colons (the ; ). At the end of every statement in C or C++, there needs to be a semi-colon to tell the computer that it's the end of a “command”. It doesn't matter how the code is spaced, or even if it's on another line, as long as it's in order and has a semi-colon telling the computer where the end is.

    The Actual Code!

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char* argv[])
    {
              cout << “Hello World!” << endl;
              cin.get();
              return 0;
    }
    Now, there are variations on it (like the one you get by default), but that's the basic Hello World program. And you're probably thinking, wtf is that? I'll try and go through it line by line. The first bit is just overhead that you'll be using in all of your dos-window programs, but it's still kind of important, so I'll explain it.

    Explanation

    Code:
    #include <iostream>
    This one's really important. This line basically tells your compiler (in simple terms the thing that turns this text file into a .exe (not really but close enough)) to basically shove a whole bunch of code up at the top of your file when it wants to turn it into an exe, essentially everything about input/output in the C++ standard library.

    I know that sounds complicated, and it is at first, but all you really need to know for now is that you really need to put that up there for your code to work. You can ignore it for now

    Code:
    using namespace std;
    This is a statement that tells the program that we're going to be using the standard namespace. Don't worry about this, you won't need to know what it means until WAY later, all you really need to know now is that you need it for cout to work.

    Code:
    int main(int argc, char* argv[])
    This is the main function, the entry-point to the program. This function tells your operating system that THIS is the starting point for your program. Everything stems from this function. The computer will start at the first line of everything inside your curly-braces ({ }), and end at the last line (or at a return statement, usually a return statement IS the last line, like in the example). When the computer gets to the end of the function, your program will end. int argc and char* argv[] are variables, you don't need to worry about them for now.

    Confused yet? Don't worry. All this stuff you won't have to deal with at first when you want to write code. What's important is that you know that basically everything in your program starts off with your first line inside int main's curly-braces, which in this case is:

    Code:
    cout << “Hello World” << endl;
    Okay. This is the important part. This is what's happening in our program! Pay attention! Don't think I don't see you snoring.

    Cout is an instance of the standard output stream class. This should mean nothing to you, so don't worry if you don't understand. All you need to know is that cout is your ticket to putting text on the user's screen.

    Basically what cout will do is take any amount of things you throw at it, and put them on the screen. When we say;

    Code:
    cout << “Hello World!”;
    We're telling the computer to take “Hello World” (without the quotations) and put it on the screen (known as printing to the screen). It's as simple as that. When we say;

    Code:
    cout << “Hello World” << endl;
    We're adding a second thing for cout to print to our screen, in this case, the end-of-line character. This just means that it'll move down a line on the screen, instead of just sitting at the end of Hello World.

    So whereas cout << “Hello World” << “Hi”; will print:

    Code:
    Hello WorldHi
    cout << “Hello World” << endl << “Hi”; will print:

    Code:
    Hello World
    Hi
    It's just a fancy way of saying move down a line. You might think this is kind of a round-about way of just saying “Hi”, but bare with me. It's necessary, and actually a really efficient way of doing things, you'll see why next lesson.

    Code:
    cin.get()
    Where cout is the thing that puts things on the screen, cin is the thing that takes stuff from the keyboard and lets you fiddle around with it in your program. This line means that you want to get the next line the user types in on their keyboard, and bring it into the program. Right now, don't worry about where this line is going; we don't care. All we're using this for is to stop the program from exiting immediately.

    If this line wasn't here, when you executed the program, a dos window would pop up for about a tenth of a second, and then disappear, we wouldn't be able to see what we've written. This way, the program waits until the user presses enter before continuing along on it's merry way.

    The last line here is pretty much the last of the overhead.

    Code:
    return 0;
    This means exit the program, and tell windows everything went fine. This should always be the last thing you put at the end of your main function.

    Running the Code

    So now. How do we actually go about running this code? Well, we do this. Go to File->Save.


    Just save it anywhere; keep it as main.cpp. This is your file that contains all your code.

    Once your file is saved, click this button. This should compile and run your code.


    You should see a dos window, with the words “Hello World” in it, and the cursor waiting on the line below. Hit enter, and the window should disappear.

    We're Done!

    And that it! I know. A lot of trouble just to put one line in a dos window. But it gets better! Soon you'll be able to put two, maybe three lines on a window :o. Seriously though, this is a good start. Everything builds on this.

    Anyway, that's this week's tutorial. I'm hoping to release these on a weekly basis, or maybe on a bi-monthly basis. This should get whoever's interested started out.

    Questions? Comments? Feedback? It's good? It sucks? Too boring? Too fast? Too long? Post anything! I'll try and clarify and fix any problems you guys might have.
    Last edited by Eriond; 11-10-2008 at 07:45 AM.
    THIS MA SIGNATURE

  2. #2
    `Doll's Dishwasher Reputation: 26
    Darkhell153's Avatar
    Join Date
    Feb 2008
    Location
    In your basement >:)
    Posts
    1,417
    Rep Power
    7

    Default

    Seems decent for a beginning tutorial. Might I recommend creating a guide like this on Wikipedia, they did the same thing with blender (which is how I'm learning to model) so I think it would work well for your tutorial too.

  3. #3
    A Shrubbery Reputation: 21
    Nuferex's Avatar
    Join Date
    Jun 2007
    Location
    Tacoma, WA
    Posts
    840
    Rep Power
    8

    Default

    Simple enough. Glad to see someone helping new comers to C++.

  4. #4
    Marios's Mustache Wax Reputation: 10

    Join Date
    Jun 2009
    Posts
    2
    Rep Power
    0

    Question What happened to the tutoruials for the Text RPG?

    Hi,

    I was wondering what ever happened to the tutorials leading up to creating your own text-based RPG? Is this another dead project/thread?

  5. #5
    Crumbly, yet Good Reputation: 75
    Eriond's Avatar
    Join Date
    May 2006
    Location
    Montreal
    Posts
    1,798
    Rep Power
    0

    Default

    Yup. Dead. No one seemed interested in it, so I just didn't bother with another one.

    Though if you want help, I'm glad to give it; want me to post another tutorial?
    THIS MA SIGNATURE

  6. #6
    Loric's Lunatic Reputation: 38
    Glavus's Avatar
    Join Date
    May 2006
    Location
    No Idea.
    Posts
    2,610
    Rep Power
    0

    Default

    Hmp, I know C++ and Java. Never thought of making a game though that's not a bad idea... As a kid I always wanted to make a game, now that I can didn't even bother to think about it.

    *Looks at date & lolz*

  7. #7
    Crumbly, yet Good Reputation: 75
    Eriond's Avatar
    Join Date
    May 2006
    Location
    Montreal
    Posts
    1,798
    Rep Power
    0

    Default

    Meh, not so long ago. This forum isn't that active
    THIS MA SIGNATURE

  8. #8
    Marios's Mustache Wax Reputation: 10

    Join Date
    Jun 2009
    Posts
    2
    Rep Power
    0

    Exclamation Yeah, I'd really like to see a continuation of the text-based RPG tutorial

    I've been using PGCC (Pocket GCC) on my T-mobile Dash and I have been able to modify the files to get it to run from a command prompt through Task Manager. As silly as it may sound, I didn't even think about using arguments or cin.get() to make the program stop and wait for a user response. So, with just those couple of tips I have been able to run the files in a console window without having to use batch files to do so. Like I said, I'd really really like to see a continuation of the text-based RPG project that isn't Wrath Lands...

  9. #9
    Marios's Mustache Wax Reputation: 10

    Join Date
    Mar 2013
    Location
    Jerusalem,Israel
    Posts
    4
    Rep Power
    0

    Default

    Eriond please help me I wanna create a Rpg please man and thanks

  10. #10
    Crumbly, yet Good Reputation: 75
    Eriond's Avatar
    Join Date
    May 2006
    Location
    Montreal
    Posts
    1,798
    Rep Power
    0

    Default

    Hi. This thread is reaaaaal old, but that's OK. Are you serious about wanting to learn?
    THIS MA SIGNATURE

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •