functions in global script

Started by geork, Mon 01/03/2010 21:15:59

Previous topic - Next topic

geork

 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

Khris

Functions can only be used below their declaration.
Simply move function 2 above function 1.

geork

 thanks for the info, but unfortunately it seems not to work. maybe I am calling the function wrong, can you simply call:
 
Code: ags
 function2(type); 
or something more specific?
   thanks
   Geork

monkey0506

It should look something like this:

Code: ags
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.

geork

 oh whoops! I put below, not above  :-\
  Anyhoo, thanks for your help! ;D

SMF spam blocked by CleanTalk