Skip to main content
GameDev.net gamedev.net
🔒 Locked

C++ Text Rpg Script Error

Started by Thermalwolf Jan 11, 2011 at 6:29 AM 6 replies 1.8k views
Original Post
Thermalwolf
Thermalwolf
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
BeerNutts
BeerNutts

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]
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)
Thermalwolf
Thermalwolf
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.
levijgraham
levijgraham
We should probably show the load.h also


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

BitMaster
BitMaster
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
The Communist Duck
The Communist Duck
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.
Thermalwolf
Thermalwolf
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.