first of all, this is one of my first times writing code so I'm a newb.
I'm writing for the nds using devkit pro, and so its all written in c++. I want to have a menu, each menu screen is a void, and I need to have a way to go back to the previous menu.
Also, I made sure that on the actual code, there is NO syntax errors (unless not being declared in this scope is considered a syntax error).
How can I do this without getting the "Error 'settings' was not declared in this scope". Code:
//Headers go here
void controls()
{
//Inits and what not go here
if (key_press & key_down)
/*This is generally how you say if the down key has been pressed (This syntax might be wrong, but ignore that part)*/
{
settings(); //This part doesn't work because it can't read back in the code
}
}
void settings()
{
//Inits and what not go here
if (key_press & key_down)
{
controls();
}
}
void mainMenu()
{
//Inits and what not go here
if (key_press & key_down)
{
settings();
}
}
AND NOTE, somewhere outside of this code, mainMenu() would get activated. So does anyone know how to code this correctly?
Thanks in advance.
At the moment of your function call, your compiler don't know anything about this function. There is two ways to make the compile aware of your function: declaration and definition.
To declare the function you have to put the function synopsis (function arguments and return values) to the top of the compilation module like this.
void settings(void);
To fix your problem you should have the settings()
function declared before the first call of it.
In your case you should probably declare the function at the top of the file. By this way compiler will be aware about the function and the arguments that should be passed into.
void settings();
void controls()
{
...
}
void settings()
{
...
}
void mainMenu()
{
...
}
Good article to start from and to get some additional details: Declaration and definition at msdn