Importing / Exporting Structs

Started by KodiakBehr, Sun 22/12/2013 17:03:58

Previous topic - Next topic

KodiakBehr

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

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?

Khris

In your header, use import lines:
Code: ags
import BadguyVariables Enemy[10];
import CrewVariables Crew[6];


In your main script, declare and export the variables:
Code: ags
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).

KodiakBehr


MiteWiseacreLives!

#3
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

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
import GridAttribute gridspot[200];


Thanks


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

GridAttribute gridspot[200];

export gridspot;


And in my header:
Code: ags

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...

SMF spam blocked by CleanTalk