Struct Array - Import / Export question [SOLVED]

Started by WHAM, Mon 05/10/2020 10:37:26

Previous topic - Next topic

WHAM

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
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
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?
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

WHAM

#1
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
struct Plot {
  int PlotType;
  int Damage;
  int Graphic;
};

import Plot Plots[40];



In the CustomFunctions script file

Code: ags
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?
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

SMF spam blocked by CleanTalk