Hello, I've been working on the tutorial for an RPG for a couple days but when I got to the bit about the menu screen (which i completed the entire section), it wasnt working correctly.
I've placed the menu code in different places and whenever I reach the point of where it's at my cmd console closes instantly, and I'm clueless as to why.
I'm assuming something is wrong with my function but I don't know where and why.
You seem to be implying that this code will compile; it doesn't even get that far for me due to mismatched braces (something the indentation should help you notice).
In any case, you are doing something very wrong here; here is your code with extraneous braces removed and a few notes.
Thanks a lot, atleast now it will continue, but there's still 1 problem.
Instead of being able to press 0 at any time your at a new location to look at your menu, the program closes. Additionally, whenever i get to the point where the menu's code is, the menu opens, which i also dont want. Heres a bit of code where you have the option to look into your menu
1 2 3 4 5 6 7 8 9 10
if(playerLocation == 3) {
cout << "You arrive to Novgorod safely and quickly.\n";
cout << "Novgorod is a large fishing town with an inn, and dusk is falling.\n";
cout << " 1: Rest in the inn.\n 2: Go south into the snow forests.\n";
cin >> userInput;
if(userInput == 1) playerLocation = 4;
elseif(userInput == 2) playerLocation = 5;
elseif(userInput == 0) void menuFuncNav();
}
Are you trying to define functions there? It looks like yes, in which case you need the return type. Perhaps it would serve you to read another tutorial on functions, which will talk about how to define and call them: http://www.cplusplus.com/doc/tutorial/functions/
Perhaps the problem is you are trying to do too much at once. Try writing a simple program that simply calls a function and see if you can get that to work.
If the function is void, it shouldn't be returning anything. Also, it looks like you're declaring a function from within your main function. I believe that's called a nested function, which isn't allowed in C++.
you should have it be like
1 2 3 4 5 6 7 8 9 10 11 12 13
void Function(); // prototype, if needed depending on order of function declarations in your program
// if you have your function declared after it's called in your main function, you'll need to have a prototype.
void Function() // Notice: no semi-colon
{
//...Do stuff...
}
int main()
{
Function();
...
}
Edit: Also, depending on your compiler, it won't compile if you don't return an integer value at the end of your main function (instead of doing return; do return 0; )
Yeah my compiler wants an interger, but 0 shuts down the program...
EDIT: I what you told me to Ganado and i fixed everything my errors told me too but the only error i got left is [Linker error] undefined reference to `WinMain@16'
I heard this can be because of my int main (Dev-C++ told me to put a semicolon after it.) So i tried doing int main(int argc, char *argv[]); and it still wont work.
Lines 25-28 (of your most recently-posted code) looks weird. Line 25 looks like a declaration of a function newGameFunc, but I don't see the definition of the function anywhere, and nor do I see that function being called anywhere.
On Line 26, you call menuFunc, but I don't see a definition for it anywhere.
Then, you open a new code block at the end of line 26, for some reason, and immediately return from main - which means that none of the following code will be executed.
Also, you've (correctly) defined main to return an int, so all the return statements should return a value.