Importing struct into room script (SOLVED)

Started by Quintaros, Fri 20/01/2006 18:40:45

Previous topic - Next topic

Quintaros

I'm still having a bit of trouble using Structs.

In my script header I define a Struct:

Code: ags

struct Goal {
  int destinationroom;
  int destinationx;
  int destinationy;
};

import Goal goal[29];


Then in my Global Script:

Code: ags

Goal goal[29]; // 29 is the number of characters in the game


Then in a room script I have a function that makes a character follow a path and to a room exit and defines the destination parameters for a ChangeRoom.

Code: ags

function FromPavilliontoFreeSea(int chara, Direction dir) {
  if (dir=eForwards) {
    character[chara].AddWayPoint(path1[1].x,  path1[1].y);
    ...
    character[chara].AddWayPoint(path1[6].x,  path1[6].y);
    goal[chara].destinationroom=3;
    goal[chara].destinationx=140;
    goal[chara].destinationy=170;
  }
  else if (dir=eBackwards) {
    character[chara].AddWayPoint(path1[5].x,  path1[5].y);
    ...
    character[chara].AddWayPoint(path1[0].x,  path1[0].y);
    goal[chara].destinationroom=24;
    goal[chara].destinationx=160;
    goal[chara].destinationy=200;
  }
}


In the before fade-in section of the room script I call the FromPavilliontoFreeSea function for one of my background characters.

And then in the RepeatedlyExecute section of the room script I call a function called UpdateGoals() which checks to see if the background character has reached the last node of his path and calls :
Code: ags
  character[i].ChangeRoom(goal[i].destinationroom,goal[i].destinationx,goal[i].destinationy);


Anyway everything compiles but when I go to the room in question the game crashes and I get the following error message:

Quote
---------------------------
Adventure Game Studio
---------------------------
An internal error has occured. Please note down the following information.
If the problem persists, contact Chris Jones.
(ACI version 2.71.894)

Error: Unable to create local script: Runtime error: unresolved import 'goal'

Could somebody please tell me what I am doing wrong?

DoorKnobHandle

#1
You should define your struct in the script header file, then just put the "importing" line in your below the definition. This will give you access to your structure in every room script file.

For the record: this is not a problem with your structure as far as I can see it; however you have messed up where to put the code.

EDIT: No, there never was a typo in here... ::)

Khris

I'm afraid that's not true, struct definitions go into the script header.

But you have to export the array if you want to import it.
A export goal; after Goal goal[29]; should solve your problem.

Quintaros

#3
Thanks...I'm still getting some strange results but its no longer crashing.

Edit: Working perfectly now.

DoorKnobHandle

Sorry for my mistake. Of course, the struct definition needs to go into the script header (before the Goal goal[29] line)...

SMF spam blocked by CleanTalk