Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: geork on Mon 01/03/2010 21:15:59

Title: functions in global script
Post by: geork on Mon 01/03/2010 21:15:59
 Hey all!
  Just a question, how can I access functions in the GlobalScript.asc which themselves are in the GlobalScript.asc (in other words, both calling and responding functions are in the GlobalScript.asc). For easy purpose, suppose the function I am currently in is Function 1, and the one I am trying to call is function 2. When I try to run the script, AGS complains that function 2 is an 'unidentified token'. No problemo, I thought, I'll just import it into GlobalScript.ash. Unfortunately, AGS now complains that: 'Already referenced name as import'.
   So now I'm a bit stuck., how can I call that function 2?
     Thanks in advance for your help.
       Geork
Title: Re: functions in global script
Post by: Khris on Mon 01/03/2010 21:18:59
Functions can only be used below their declaration.
Simply move function 2 above function 1.
Title: Re: functions in global script
Post by: geork on Mon 01/03/2010 21:37:39
 thanks for the info, but unfortunately it seems not to work. maybe I am calling the function wrong, can you simply call:
  function2(type); or something more specific?
   thanks
   Geork
Title: Re: functions in global script
Post by: monkey0506 on Mon 01/03/2010 23:35:30
It should look something like this:

function function2(int param) {
 // .. do some stuff here ..
}

function function1(int param) {
 // .. do some stuff here ..
 function2(param); // call function2
 // .. do some more stuff ..
}


If you need both functions to be able to call each other it's possible using a helper function with recursion.
Title: Re: functions in global script
Post by: geork on Tue 02/03/2010 19:34:07
 oh whoops! I put below, not above  :-\
  Anyhoo, thanks for your help! ;D