Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Dadalus on Mon 25/08/2014 20:31:52

Title: [SOLVED] Initializing struct integer array in game_start
Post by: Dadalus on Mon 25/08/2014 20:31:52
I have an odd problem that for the life of me I cant figure out. I have a struct containing an integer array and a function that initializes the arrays values.

Header:
Code (ags) Select
struct stUserEvents
{
  int eventqueue[NUMBER_EVENTS];
  import void Initialise();
};

stUserEvents UserEvent;

script:
Code (ags) Select
void stUserEvents::Initialise()
{
  int intLoop=0;
  while (intLoop<NUMBER_EVENTS)
  {
    this.eventqueue[intLoop]=eNoEvent;
    intLoop++;
  }
}


in game_start I have
Code (ags) Select
UserEvent.Initialise();

trouble is the values are not being set.

If I take out the integer array from the struct and place it in my script

Code (ags) Select
int eventqueue[NUMBER_EVENTS];

void stUserEvents::Initialise()
{
  int intLoop=0;
  while (intLoop<NUMBER_EVENTS)
  {
    eventqueue[intLoop]=eNoEvent;
    intLoop++;
  }
}


the values are set.

Can anyone tell me what I am not seeing, I'm assuming its just down to my rusty skills and me just not getting some principle.
Title: Re: Initializing struct integer array in game_start
Post by: Khris on Mon 25/08/2014 22:05:14
You're declaring the instance in the header, which creates a separate instance for each script. You need to do:
Code (ags) Select
// header
import stUserEvents UserEvent;

// script
stUserEvents UserEvent;
export UserEvent;
Title: Re: Initializing struct integer array in game_start
Post by: Dadalus on Mon 25/08/2014 22:19:42
Thanks Khris , that sorted it. I could have sworn Id tried using 'export' but I must have not included the 'import'.