Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Wayne Adams on Mon 16/02/2009 04:44:02

Title: Function exists, error code insists it doesn't
Post by: Wayne Adams on Mon 16/02/2009 04:44:02
searched the forums for this, don't understand why AGS gives me the undefined token error 

this is the code:

#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
  {
  if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
    {
    }
  else if (button == eMouseLeft)
    {
    ProcessClick(mouse.x,201, mouse.Mode);
    }
  else // right-click, so cycle cursor
    {   
    if (button == eMouseRight)
Display ("HUD should pop up");
gMain_menu_Click();


    }
  }
#sectionend on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart interface_click  // DO NOT EDIT OR REMOVE THIS LINE
function interface_click(int interface, int button)
  {
  }
#sectionend interface_click  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart gMain_menu_Click  // DO NOT EDIT OR REMOVE THIS LINE
function gMain_menu_Click(GUI *theGui, MouseButton button)
{
gMain_menu.SetPosition(player.x, player.y);

 
}
#sectionend gMain_menu_Click  // DO NOT EDIT OR REMOVE THIS LINE



gMain_menu_Click exists.. but trying to call it gives me the error.. what did i do wrong?

Thanks
Title: Re: Function exists, error code insists it doesn't
Post by: Trent R on Mon 16/02/2009 05:39:30
Because the script is read from the top to the bottom. But you're calling something that doesn't exist until x amount of lines down.

Just move the gMain_menu_Click function above on_mouse_click.


~Trent
PS-Are you sure you don't mean mouse.x and mouse.y, instead of player.x and player.y?
Title: Re: Function exists, error code insists it doesn't
Post by: Wayne Adams on Mon 16/02/2009 06:01:17
thanks Trent, and yeah, i want the HUD to pop on top of the player

EDIT: Moved the function above on_mouse_click, editor still says the token is undefined..

Trent, I always thought functions were written at the end of code.
The main loop calls functions written at the bottom.. of course the last time i did serious coding, i used GOSUBs.. so I'm pretty rusty..

EDIT: Function works now, my kung fu is getting stronger i guess.