Forum Thread
Search
by member
  Posts  
Coding a Text Based RPG - Game won't continue (Forums : Coding & Scripting : Coding a Text Based RPG - Game won't continue) Locked
Thread Options
ArChNeMiSiS
ArChNeMiSiS Say hello to my little friend!
May 10 2008, 1:47am Anchor

Hey guys.

I've started a little project to improve my coding abilities. It will be a text-based RPG.

Now I've got the program to build and run fine, but there is a point right after the intro that will not load.

I've got a couple of .cpp files and a few .h files and like I said everything is running fine.

Here is my main.cpp file which has the welcome screen:
 

Quote:#include "Library.h"

voidmain()
{
      // GENERIC WELCOME SCREEN
      cout <<"=========================ETERNA: THE FORGOTTEN LANDS=========================\n\n";
      cout <<"----------------------------------------------------------------\n";
      cout <<"Programmed by Matthew Patterson\n";
      cout <<"----------------------------------------------------------------\n\n"; 

      cout <<"An Evil Demon Lord has dispatched his minions across the land\n to pilage and loot unsuspecting people. It is up to you,\n the hero, to rise up and remove the Demon Lord of his power!\n\n";

     Wait();
   
    Crossroads();

    cout <<"\n\nThank you for playing ETERNA: THE FORGOTTEN LANDS! Please play again soon.\n\n"; } 



So as you can see, my main.cpp file starts up and displays the above text. The "Wait" function is defined in the Library.h file and basically asks for the player to "Press Enter to Continue". After that the line cin.ignore(1); is used to ingnore the keystroke and continue the code.

Now all of that runs fine. I build with no errors, and run the game. The above is displayed and the "Press Enter to Continue" is displayed as well. Now when I press enter, the little dash/stroke/line that flashes moves down a line. So I'm guessing it works.

Now the crossroads.cpp file is meant to open and display it's text...problem is, it doesn't. Now this isn't because of the "Wait" function because I tried running the game without it and the game does the same thing, the crossroads.cpp doesn't run.

Here is the crossroads.cpp file:

Quote:#include "Library.h"

// Crossroads

// GLOBAL VARIABLES
bool glcomplete = false;
bool focomplete = false;
bool swcomplete = false;
bool gycomplete = false;
bool cacomplete = false;

bool Crossroads()
{
      int choice = 0;
      while (choice != 10); 
      {
            cout <<"You stand in the center of several roads going off in many directions.\n";
            cout <<"There is a small town behind you full of shops and people.\n\n"; 
           
            cout <<"Which path do you wish to take?\n"; 
            cout <<"1) Town\n"; 
            cout <<"2) Summoning Portal\n"; 
              
             if (!glcomplete)
                  cout <<"3) Grasslands Road [QUEST]\n";
             if (glcomplete && !focomplete)
                 cout <<"4) Forest Road [QUEST]\n";
             if (focomplete && !swcomplete)
                 cout <<"5) Swamp Road [QUEST]\n";
             if (swcomplete && !gycomplete)
                 cout <<"6) Graveyard Road [QUEST]\n";
             if (gycomplete && !cacomplete)
                 cout <<"7) Castle Road [QUEST]\n";

            cout <<"10) Exit Game\n";
            cout <<">";
            cin >> choice;
            }
        return true;



As I said before, everything built fine with no errors. I'm loosely following a template and it runs well. The thing that gets me is why this won't work...

I'm using Visual C++ Express 2008 if that is of some importance...

So yeah, if anyone has any idea, I would greatly appreciate it.

Gibberstein
Gibberstein Generic Coder Type Thing
May 10 2008, 2:31am Anchor

In this line:

while (choice != 10);

remove the semicolon thus:

while (choice != 10)

PS: go google debugging and breakpoints. If you knew how to single-step through in a debug build, you'd spot this mistake yourself pretty easily :)

--

"lets say Portal is a puzzle game, so its a rehash of Tetris"
- Wraiyth points out the craziness of stereotyping games by their genre

ArChNeMiSiS
ArChNeMiSiS Say hello to my little friend!
May 10 2008, 3:02am Anchor

Ahh thanks Gibberstein.

I feel a little stupid now :nervous:

Thanks again.

--

User Posted Image

Gibberstein
Gibberstein Generic Coder Type Thing
May 10 2008, 3:42am Anchor

Glad to help. Don't feel stupid, it''s the sort of mistake we all make at least once ;)

--

"lets say Portal is a puzzle game, so its a rehash of Tetris"
- Wraiyth points out the craziness of stereotyping games by their genre

Dark_Raver9
Dark_Raver9 Gwaa?..
May 10 2008, 4:42am Anchor

as long as you learn from your mistakes, then they are never stupid :D

--

Currently doing: Nothing...someone??? :p

Bytrix
Bytrix Annihilation Developer
May 12 2008, 9:08am Anchor
Gibberstein wrote:it''s the sort of mistake we all make at least once ;)

Or a few hundred times when you've been coding as long as some of us :rolleyes:

--

Has anyone seen my companion cube?

May 12 2008, 4:10pm Anchor
Bytrix wrote:
Gibberstein wrote:it''s the sort of mistake we all make at least once ;)

Or a few hundred times when you've been coding as long as some of us :rolleyes:


Or when your just forgetful like me. :|

Edited by: Ninjadave

Wraiyth
Wraiyth That Guy Who Does Those Things With The Stuff
May 12 2008, 4:24pm Anchor
Quote:// GLOBAL VARIABLES
bool glcomplete = false;
bool focomplete = false;
bool swcomplete = false;
bool gycomplete = false;
bool cacomplete = false;

Rule of Thumb: Don't do this. Never, under any circumstance, use global variables. They enforce bad code structure and lazy programming.

ArChNeMiSiS
ArChNeMiSiS Say hello to my little friend!
May 12 2008, 10:51pm Anchor

Roger, I'll implement it elsewhere.

ATM, I'm trying to get the basics in then I'll go back and edit, I know it is lazy and can lead to major errors and mess, but rest assured that I'm learning alot about error finding and bug squashing in the process :P

--

User Posted Image

May 12 2008, 11:41pm Anchor

Global Variables have their uses. Known constants that won't change and are long are useful, such as pi or names that you think could change and get used everywhere that is not really variable. In the Pi example, you could have for a global variable
float pi=3.14xxxxxxxxxxxxxxx; and have extremely accurate calculations. The name example was given by my programming professor; the exact example he gave was using a global variable for the school name because they changed the name of the school and said it would be a real pain to have to go and change all instances of the old name with the new one instead of making just one change in the various programs the school used.

Now, Wraiyth is correct in saying that you should avoid the usage of global variables, but they do serve a purpose and can be extremely useful with a little foresight into what you are going to be using it for.

As for where you should put those variables, you should put them in the function that uses them and since I don't see any commands that change the state of those bools, I suggest you make them parameters of the function right below them.

And also, you're Crossroads function is useless right now. You return a value but you don't save it in main. You should have something like bool choice=Crossroads(parameters); so that you can save the value returned, or make Crossroads a void type since in its current use, the return is wasted. It's less processing for the computer to do and efficiency is always good.

Edited by: Azaral

Gibberstein
Gibberstein Generic Coder Type Thing
May 13 2008, 2:32am Anchor
Azaral wrote:The name example was given by my programming professor; the exact example he gave was using a global variable for the school name because they changed the name of the school and said it would be a real pain to have to go and change all instances of the old name with the new one instead of making just one change in the various programs the school used.

I really hope that was just an example for a beginning programming class, not a serious suggestion for working programmers. That sort of data should be in a file external to the program. If you have to recompile the executable to change something like that, you have a very shoddy program.

--

"lets say Portal is a puzzle game, so its a rehash of Tetris"
- Wraiyth points out the craziness of stereotyping games by their genre

Wraiyth
Wraiyth That Guy Who Does Those Things With The Stuff
May 13 2008, 3:58am Anchor
Quote:Global Variables have their uses. Known constants that won't change and are long are useful, such as pi or names that you think could change and get used everywhere that is not really variable.

They aren't global variables. They're global constants, which ARE useful and are generally encouraged for things that you're going to use often and don't want to always type out. Pi is ALWAYS the example given here

May 13 2008, 6:02am Anchor

It was a basic programming class.

Reply to Thread

Only registered members can share their thoughts. So come on! Join the Mod DB community today (totally free) and join in the conversation.