Help with Ghosts Tutoial (make a gui): repeatedly_execute function (solved)

Started by BlueAngel, Sun 27/12/2009 11:49:17

Previous topic - Next topic

BlueAngel

Hi
I trying to make my first gui using Ghost tutorial but get a error message: Error (line 60): Undefined token'myCreateScummText'

I have made the function, it was when I put it in the repeatedly execute function it stoped working.
Hope someone understand what Im trying to say and here is the code:
Code: ags
 
function repeatedly_execute() {  // put anything you want to happen every game cycle, even when the game is paused, here
 
  myCreateScummText(); 
  if (IsGamePaused() == 1) return;  // put anything you want to happen every game cycle, but not when the game is paused, here
}


Code: ags
function myCreateScummText ()
{
  if (mouse.Mode == eModeWalkto) { lblScummText.Text = "walk to";}
  if (mouse.Mode == eModeLookat) { lblScummText.Text = "look at";}
  if (mouse.Mode == eModePickup) { lblScummText.Text = "take";}
  if (mouse.Mode == eModeInteract) { lblScummText.Text = "use";}
  if (mouse.Mode == eModeTalkto) { lblScummText.Text = "talk to";}
  
  if (mouse.Mode == eModeUseinv) { lblScummText.Text = "use";
                      lblScummText.Text = lblScummText.Text.Append(player.ActiveInventory.Name);
                      if(Game.GetLocationName(mouse.x, mouse.y)!=player.ActiveInventory.Name){
                        lblScummText.Text=lblScummText.Text.Append("on");
                        lblScummText.Text=lblScummText.Text.Append(Game.GetLocationName(mouse.x, mouse.y));
                      }
                     }
  if (mouse.Mode!= eModeUseinv) { lblScummText.Text = lblScummText.Text.Append (Game.GetLocationName(mouse.x, mouse.y));}
}



ThreeOhFour

Did you make sure you put the mrCreateScummText() function before repeatedly_execute in the game's global script?


ThreeOhFour



monkey0506

Aww how cute, lil' Ben teaching people about programming stuff. :=

Just to clarify the reasoning behind it, some languages allow you to forward declare functions (tells the compiler you're going to define function X later on so you can use it now) or even just call functions before their defined without a declaration, but AGS does not. You can only call a function in AGS that has already been defined. So for example:

Code: ags
function func_A() {
  func_B();
}

function func_B() {
  // ...
}


Will not work in AGS because when it comes to func_A then func_B hasn't yet been defined. However, reversing it such as:

Code: ags
function func_B() {
  // ...
}

function func_A() {
  func_B();
}


Will work. If you ever find that you need portions of two functions to both call each other, consider splitting those functions into smaller utility functions so they can both call the appropriate bits of code as needed. ;)

ThreeOhFour

Quote from: monkey_05_06 on Sun 27/12/2009 19:22:08
Aww how cute, lil' Ben teaching people about programming stuff. :=

Hee hee I tricked her into thinking I am smart  ;D


SMF spam blocked by CleanTalk