Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: KodiakBehr on Sun 22/12/2013 17:03:58

Title: Importing / Exporting Structs
Post by: KodiakBehr on Sun 22/12/2013 17:03:58
I know this is a common question, but I still can't quite get my head around how the solutions offered would apply to my specific case.

I have two structs and two arrays.

Code (ags) Select

struct CrewVariables{
  int floor;
  int health;
  String name;
  };

struct BadguyVariables{
  int Distance;
  int HP;
  String name;
  };

BadguyVariables Enemy[10];
CrewVariables Crew[6];


They were working fine as a general definition in GlobalScript.asc, but now I need to move that information between the GlobalScript.ash and Room 1, so I've moved the structs now to the GlobalScript.ash header instead, and kept the arrays in the .asc.  What do I put in the general definitions of the .asc and Room 1 in order to move all this information around?
Title: Re: Importing / Exporting Structs
Post by: Khris on Sun 22/12/2013 17:14:29
In your header, use import lines:
Code (ags) Select
import BadguyVariables Enemy[10];
import CrewVariables Crew[6];


In your main script, declare and export the variables:
Code (ags) Select
BadguyVariables Enemy[10];
CrewVariables Crew[6];
export Enemy, Crew;


If you only need them in Room 1, you can import them there instead (the header is put on top of every room script).
Title: Re: Importing / Exporting Structs
Post by: KodiakBehr on Sun 22/12/2013 19:22:34
Got it.  Thanks again!
Title: Re: Importing / Exporting Structs
Post by: MiteWiseacreLives! on Wed 25/10/2017 21:58:59
Sorry this is an old one..
I cannot get this method to work though, i get the error:

Failed to save room room1.crm; details below
GlobalScript.ash(6): Error (line 6): expected variable or function after import, not 'GridAttribute'

In my GlobalScript:
Code (ags) Select

struct GridAttribute
{
  bool walking;
  bool swimming;
  int resource1;
  int resource2;
  int resourceQuantity1;
  int resourceQuantity2;
};

GridAttribute gridspot[200];

export gridspot;


And in my header:
Code (ags) Select
import GridAttribute gridspot[200];

Thanks


EDIT:
  I did some searching the beginners forum.. I should have:
In my GlobalScript:
Code (ags) Select

GridAttribute gridspot[200];

export gridspot;


And in my header:
Code (ags) Select

struct GridAttribute
{
  bool walking;
  bool swimming;
  int resource1;
  int resource2;
  int resourceQuantity1;
  int resourceQuantity2;
};
import GridAttribute gridspot[200];


Sorry about that, maybe this will help the next AGS'r...