Hello. I'm trying to get along with scripting and can't find answer to my problem . I spended 3 hours in internet surfing for it and finally came here for help..
Here is my script.
function game_start()
{
MainMenuGUI(gNewGame);
cCaptain.SetIdleView(2, 0);
}
and the function itself
function MainMenuGUI(GUI *theGui)
{
if (theGui == gNewGame)
{
PauseGame();
gNewGame.Visible = true;
}
}
When i trying to run game i get:
GlobalScript.asc(7): Error (line 7): Undefined token 'MainMenuGUI'
Please help to acknowledge this..
With Best Regards
You can only call a function after you have defined it. Move your custom function above game_start().
Thank you very much! It was soo simple... ^) By the way i think it's nowhere documented about placing custom functions before game_start().
Thank you again!
Not before game_start- every function must be above any other function that calls it. Modern(er) programming languages allow you to place functions whereever your want, but AGs (being RETRO!) requires this style of declaration :P
To elaborate on this issue: Modern programming languages such as Java and C# that do not require functions to be implemented before they are called do this at the expense of compile time. They use a so-called two-pass compiler, which scans every code file twice - once just to grab all the signatures of all functions/classes/etc and then a second time for the actual implementation. C/C++ and AGS script only runs through your script once, so you need to pay attention to the order of functions or put in prototypes - but your code, as a result, compiles a bit faster. So, long story short, it's not a bug - it's a FEATURE! :)