| 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 | ||
|
|
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() 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(); 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 Crossroads() cout <<"10) Exit Game\n"; 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. |
||
|
|
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" |
||
|
|
May 10 2008, 3:02am Anchor | |
|
|
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" |
||
|
|
May 10 2008, 4:42am Anchor | |
|
as long as you learn from your mistakes, then they are never stupid --
Currently doing: Nothing...someone??? :p |
||
|
|
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 -- 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 Or when your just forgetful like me. Edited by: Ninjadave |
||
|
|
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. |
||
|
|
May 12 2008, 10:51pm Anchor | |
| 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 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 |
||
|
|
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" |
||
|
|
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. |
||
Only registered members can share their thoughts. So come on! Join the Mod DB community today (totally free) and join in the conversation.