Public Group

# C++ Text Rpg Script Error

This topic is 2811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So my friend and I are starting our first game, a text based rpg. Now it's only a few hours in but we are stuck with this problem.

#include "load.h" #include <string> #include <iostream> static enum StringValue(choice) { choice["newgame"] = choiceNewGame; choice["loadgame"] = choiceLoadGame; } 

When you try and compile this is the error:
load.cpp(6): error C2470: 'choice' : looks like a function definition, but there is no parameter list; skipping apparent body

I don't understand. I'm sure I have everything in the right place

##### Share on other sites

So my friend and I are starting our first game, a text based rpg. Now it's only a few hours in but we are stuck with this problem.

#include "load.h" #include <string> #include <iostream> static enum StringValue(choice) { choice["newgame"] = choiceNewGame; choice["loadgame"] = choiceLoadGame; } 

When you try and compile this is the error:
load.cpp(6): error C2470: 'choice' : looks like a function definition, but there is no parameter list; skipping apparent body

I don't understand. I'm sure I have everything in the right place

[font="calibri, verdana, tahoma, sans-serif"][color="#000088"]static [color="#000088"]enum [color="#660066"]StringValue[color="#666600"]([color="#000000"]choice[color="#666600"])[/font]
[font="calibri, verdana, tahoma, sans-serif"] [/font]
[font="calibri, verdana, tahoma, sans-serif"][color="#666600"]The definition above doesn't make sense. You're defining a function as a static enum (what kind of enum?) And the parameter is choice (what type of variable is choice?).[/font]
[font="calibri, verdana, tahoma, sans-serif"] [/font]
[font="Courier New"][color="#666600"]I don't even think you're meaning to define a function, as it looks like you're trying to define an enum named StringValue, but you've gone about it incorrectly as well. [/font]
[font="Courier New"][color="#666600"] [/font]
[font="Courier New"][color="#666600"]Regardless, I don't think C++ supports using strings as enum indexes, so the code inside the function (or the variable declaration) won't be proper either.[/font]
[font="Courier New"][color="#666600"] [/font]
[font="Courier New"][color="#666600"]You also need to provide what "choiceNewGame" and "choiceLoadGame" mean and how they're defined (are they variables? Functions? Objects?)[/font]
[font="Courier New"][color="#666600"] [/font]
[font="Courier New"][color="#666600"]You better go back and read the chapters again as I think you've missed alot here.[/font]
[font="Courier New"][color="#666600"] [/font]
[font="Courier New"][color="#666600"]
[/font]I'm sure I have everything in the right place[/quote]

[font="Courier New"][color="#666600"]Maybe not.[/font]

##### Share on other sites
Ok I'm sorry I didn't explain exactly what I was doing. This file is separate to keep things clean. I'm using it in a case.

#include <iostream> #include <string> #include "load.h" #include "NewGame.h" int main() { using namespace std; int choice; cout << "****************************************\n"; cout << "* Welcome to TEXT BASED ADVENTURES!!!! *\n"; cout << "****************************************\n"; cout << "* NewGame *\n* LoadGame *\n************" << endl; cin >> choice; switch (choice) { case choiceNewGame: newgame(); break; case choiceLoadGame: cout << "No load game detected!" << endl; break; default: cout << "Not a valid entry..." << endl; break; } system("pause"); return 0; }

Theirs the main code we have so far. See if this helps in figuring out my issue unless it's still all the same as from what you've said above.

##### Share on other sites
We should probably show the load.h also

 #ifndef LOAD_H #define LOAD_H static enum StringValue { choiceNewGame, choiceLoadGame, }; #endif

##### Share on other sites
If this is meant to be C++ it might help if you said what you want to do. Because at the time being I'm only sure of two things:

1) This is not legal C++

2) I have no clue what you want to do

##### Share on other sites
From what I can see the file containing your main function is valid C++, but please explain what you're trying to do in the other two files.

##### Share on other sites
I can see what you want to do. You to take user input, and then go to either new game or load game. However, you cannot take input from cin directly to an enum. Instead, try to implement something like:

*Press 'n' for a new game
*Press 'l' to load an existing game

Then:

 char choice; cin >> choice; //Read in the user input into choice if(choice == 'n' || choice == 'N') //Lower case OR upper case { /*new game*/ } else if(choice == 'l' || choice == 'L') { /*load*/ } else { //invalid input std::cout << "Error, choose a valid option please.\n"; } 

Of course, this lacks error handling and querying for more input if error'd, and there's a function to uppercase characters (so you wouldn't have to check 'n' AND 'N') but my C++ is rusty.

##### Share on other sites
Yes dude that is exactly what we wanted to do, I thought I explained and showed enough but you got it. I'll give that code a try thank you very much

1. 1
2. 2
Rutin
21
3. 3
4. 4
5. 5
frob
12

• 17
• 9
• 31
• 16
• 9
• ### Forum Statistics

• Total Topics
632614
• Total Posts
3007440

×