[SOLVED] Initializing struct integer array in game_start

Started by Dadalus, Mon 25/08/2014 20:31:52

Previous topic - Next topic

Dadalus

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
struct stUserEvents 
{ 
  int eventqueue[NUMBER_EVENTS];
  import void Initialise(); 
};

stUserEvents UserEvent;

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


in game_start I have
Code: ags
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
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.
This has been a 'Mouse fetishist' approved message.

Khris

You're declaring the instance in the header, which creates a separate instance for each script. You need to do:
Code: ags
// header
import stUserEvents UserEvent;

// script
stUserEvents UserEvent;
export UserEvent;

Dadalus

Thanks Khris , that sorted it. I could have sworn Id tried using 'export' but I must have not included the 'import'.
This has been a 'Mouse fetishist' approved message.

SMF spam blocked by CleanTalk