Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: WHAM on Mon 05/10/2020 10:37:26

Title: Struct Array - Import / Export question [SOLVED]
Post by: WHAM on Mon 05/10/2020 10:37:26
I tried reading up on the search results and found others with similar issues, but wasn't able to quite figure this out, so maybe someone can help me figure this out.

I have created a new script file CustomFunctions to keep certain data and functions separate from the global script, for clarity. I have also added the line for importing it, so it can be used in the global script as well as the various rooms.

In the CustomFunctions.ash (header) I have declared a struct

Code (ags) Select
struct Plot {
  int PlotType;
  int Damage;
  int Graphic;
};

import Plot Plots[40];


However, I was unable to figure out where I should put the export that would pair up with the import.

Currently, trying to write into the array from another script file returns the error
-------
Loading game failed with error:
Script link failed.
Runtime error: unresolved import 'Plots'.

The game files may be incomplete, corrupt or from unsupported version of AGS.
-------


This makes sense, as I am missing the export.

However, attempting to place an export into the CustomFunctions.asc, outside of any function as when exporting functions, like so:
Code (ags) Select
export Plots[40];

Results in the error:
Cannot export an import

Either the location or syntax of the export, or perhaps import, is invalid, but I cannot figure out which one, or how?
Title: Re: Struct Array - Import / Export question
Post by: WHAM on Mon 05/10/2020 10:49:54
Self solved, thanks to coming across: https://www.adventuregamestudio.co.uk/forums/index.php?topic=34618.msg452801

I had the array definition and export missing, and that thread pointed out the right way to do it.

EDIT:
For clarity, here is my final version:

In the CustomFunctions header:

Code (ags) Select
struct Plot {
  int PlotType;
  int Damage;
  int Graphic;
};

import Plot Plots[40];



In the CustomFunctions script file

Code (ags) Select
Plot Plots[40];
export Plots;


EDIT2: I can't help but say "Plot Plots" out loud whenever I see it written. Is this a bug?