Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: EnterTheStory (aka tolworthy) on Fri 28/03/2008 18:12:45

Title: where to import and export? (SOLVED)
Post by: EnterTheStory (aka tolworthy) on Fri 28/03/2008 18:12:45
Can someone clarify where variables can be imported and exported?

//this is declared near the top of the global script:
int name[300];
String name2[300];
int name3[300];

//this is at the bottom of the global script:
export name[300];
export name2[300];
export name3[300];

// this is imported in the script header
import int name[300];
import String name2[300];
import int name3[300];

// this is called in a module:
if(name2[n] == "bla bla bla"){}

This compiles happily. But when I run the game I get:
" Script link failed: Runtime error: unresolved import 'name2' "

So I imported it in the module header instead: same result.

I searched the forums, and found the following advice:
"You can only export a variable from the global script"
and
"You need to export the variable in the one place where it is declared, which should be the first script in the order in which scripts are listed. The global script is usually the last script."

Now I am more confused! Is the global script compiled after the other modules? Should variables be declared and exported earlier then? Am I getting rooms and modules confused? Or is my real problem that I'm trying to export an array of String? Any advice would be appreciated.
Title: Re: where to import and export? ("unresolved import" error)
Post by: Pumaman on Fri 28/03/2008 18:24:12
Try replacing this:

//this is at the bottom of the global script:
export name[300];
export name2[300];
export name3[300];

with this:

//this is at the bottom of the global script:
export name;
export name2;
export name3;

But also, you need to export variables in a module BEFORE the one you try to use them in.

So if you export them from the global script, you can only use them in room scripts.

If you want to be able to use them in all modules, then add a new module at the top of the list that has those variables in it.
Title: Re: where to import and export? (solved, I think)
Post by: EnterTheStory (aka tolworthy) on Fri 28/03/2008 18:39:30
Thanks - I'll do that.

Edit:
Now I understand! Modules come first, then the global script, then the rooms. This import and export malarky finally makes sense to me. :)

Thanks again