Every time I try and follow this tutorial I seem to get a problem when it comes to adding in the functions as directed in the tutorial. No matter what I do I seem to keep getting errors when I add in the function under the int main
void titleFunc() {
cout << "\t\t\t\t---Fantasee---\n\n\n"; // Display the title
cout << "\t\t\t\t 1: Play\n"; // Display the options
return;
I have already declared this function above main and have followed the tutorial to the letter numerous times and I was wondering if anyone can spot what I am doing wrong or is this a problem in the tutorial.
If you have, you're going to need to show us more of your code.
PLEASE USE CODE TAGS (the <> formatting button) when posting code. http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
hey thx again, the errors I where getting were - error a function-definition is not allowed before "{" and when I originally tried fixing it I got many more errors (I think I broke it more).
I am a little worried about this tutorial now if it is showing me step by step the wrong code. Does anyone know of any good beginning game design tutorials for a text based RPG.
I am a little worried about this tutorial now if it is giving showing me step by step the wrong code.
Looks fine to me.
This is what I get when I follow the instruction on the page you posted a link to. It compiles and runs fine, though you have to ctrl-C to get out of it. (And looks pretty much the same as Superdude's take.)
#include<iostream>
usingnamespace std;
bool running = 1;
int userInput = 0;
void titleFunc(); // Handles the title screen
int main() {
titleFunc();
while(running) {
}
return 0;
}
void titleFunc() {
cout << "\t\t\t\t---Fantasee---\n\n\n";
cout << "\t\t\t\t 1: Play\n";
cin >> userInput;
if(userInput == 1) {
/* We will insert the new game code here and then the
program will continue in its loop, playing the game */
}
else {
running = 0; // If the user does not enter a valid command, we will terminate the program
}
return;
}
Like Daleth, I think the return; at the end of titleFunc() is pointless, though benign.
ahh ok thanks alot Andy, I think its me making silly mistakes and reading things wrong. Ive spent the last 7 days non stop reading code and doing tutorials I think my brain is melting.
I will try and get through the rest of the tutorial, wish me luck.
Hi guys just a quick question, I have followed the tutorial even further and I was just wondering why the else (Line 38) in my if statement does not appear to be running correctly. I can press any button and the program will carry on through the next choices.
#include <iostream>
usingnamespace std;
bool running = 1; //allows easy termination of the program
void titleFunc(); //Title Screen Function
int userInput = 0;
void newGameFunc(); //Handles creating a new game
int playerInfo[2]; //change to however many options the player is going to pick
int playerLocation = 0; //Stores a numerical reference to the location of the player
int main(){
titleFunc();
newGameFunc();
while(running){ //Will continue to loop while running is one
if(playerLocation == 1){
cout << "You are standing in the middle of a forest. A path veers off to the East and to the West\n";
cout << " 1: Go East\n 2: Go West\n";
cin >> userInput;
if(userInput == 1) playerLocation = 2; //East
elseif (userInput == 2) playerLocation = 3; //West
}
}
return 0;
}
void titleFunc() {
cout << "\t\t\t\t---Dungeon Raiders---\n\n\n"; //displays title
cout << "\t\t\t\t 1: Play\n"; //displays the options
cin >> userInput;
if(userInput == 1) {
newGameFunc(); //creates a new game
}
else {
running = 0; //terminate if user does not enter a valid command
}
return;
}
void newGameFunc() {
cout << "Welcome to Dungeon Raiders, a world of adventure and danger.\n";
cout << "Since you are a new hero, why don't you tell me a little about yourself?\n";
cout << "For starters, are you Male or Female?\n 1: Male\n 2: Female\n";
cin >> userInput;
playerInfo[0] = userInput; //store the players gender in the relevant section of the array
cout << "And what kind of person are you?\n 1: Warrior\n 2: Archer\n 3: All-rounder\n";
cin >> userInput;
playerInfo[1] = userInput; // store what class the player is in the array
playerLocation = 1; // Place the player in the start area
return;
}
Iam also seeing that I need to select my character class and gender twice before it lets me enter the game.