Calling Functions Cross-Package [Solved]

Started by parmeisan, Fri 24/02/2012 23:08:28

Previous topic - Next topic

parmeisan

Hi,

I wasn't able to find anything on this, but I may simply be searching the wrong terms.  Feel free to answer with just a link to another thread.  :)

I have a function in GlobalScript which calls several lines from another package (SCUMM_VERBCOIN_GUI).  This works fine, and that function is called SetVerbCoin.

I also have a package called General, and although it would probably work to just remove this package completely and put everything in GlobalScript, I'd rather not do this.  A function in General needs to call SetVerbCoin.  I can't seem to say anything like "GlobalScript.SetVerbCoin".  Nor can I move this function to General, because although GlobalScript can call functions from General, General does not seem to be able to call functions from SCUMM_VERBCOIN_GUI.


I'm a pretty visual person, so I thought this diagram might help to see what I mean:

http://agile-games.net/misc/images/functions.png

Ryan Timothy B

Unfortunately AGS is very limited in this manner. It can only access elements from scripts placed above the current script that is calling it. Same with functions. But every Room script can access any 'global' function from any of the global scripts.

Any function in the scripts that would need to be called in Room scripts or any scripts below it, would need to be imported into the Header script.

Header script:
Code: ags

import function Whatever();


Code: ags

function Whatever()
{
  //whatever lol
}

parmeisan

I'm not sure precisely where you're saying to use import, but I think I've already done that because I have imports all over my header files.  Anyway, what you said about the ordering is spot on, because all I needed to do was right-click on General under scripts and choose "Move down" until it was below SCUMM_Verbcoin_GUI.  That let me define the function again in General, which is an acceptable solution (although the career programmer in me winces a bit).  Strangely, I can't move GlobalScripts up, which makes it not all that Global.

So... sweet!  This forum is now 2 for 2 on solving my problems in a single response.  You guys are awesome.  Thank you.

Khris

You can't move the GlobalScript up because all other scripts are basically outsourced parts of it.
The more general a script is, the further up it's supposed to go in the script tree.
Headers are put in front of all subsequent scripts at compile time.

SMF spam blocked by CleanTalk