C++ Text Rpg Script Error

Started by
6 comments, last by Thermalwolf 13 years, 3 months ago
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 :(
Advertisement

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

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)

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.
We should probably show the load.h also


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

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
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.
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.
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 :)

This topic is closed to new replies.

Advertisement