Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Recluse on Mon 10/12/2007 01:51:27

Title: [SOLVED] Managed types, arrays, and pointers.
Post by: Recluse on Mon 10/12/2007 01:51:27
Alright, I've recently come across a new keyword "managed" in my dealings with AGS scripts. It's killing me.

I've tried two different sets of code, neither one will work. I know it's entirely possible to do this in other languages, and It's even mentioned in the AGS help files, so I know it's possible. I'm just doing something horribly horribly wrong.

Here's my code:

struct door{
  Object* DoorObject;
  int WalkToX;
  int WalkToY;
  int ToRoomID;
  int ToRoomX;
  int ToRoomY;
};

door Doors[25]; // array to store door objects in
int TotalDoors = 0; // index for the array


function CreateDoor(this Object*, int WalkToX, int WalkToY, int ToRoomID, int ToRoomX, int ToRoomY)
{
  door Door;
  Doors[TotalDoors] = Door;
}


I get an error with the above code that tells me me that I can't assign a door struct to the Doors[] array.

That's all well and good, so I change the array to deal with pointers. Changes are highlighted in bold.

managed struct door{
  Object* DoorObject;
  int WalkToX;
  int WalkToY;
  int ToRoomID;
  int ToRoomX;
  int ToRoomY;
};

door* Doors[25]; // array to store door objects in
int TotalDoors = 0; // index for the array

function CreateDoor(this Object*, int WalkToX, int WalkToY, int ToRoomID, int ToRoomX, int ToRoomY)
{
  door Door;
  Doors[TotalDoors] = &Door;
}
}


And that tells me that I can't "declare a local instance of a managed type".

I've tried inserting the "new" operator in the CreateDoor(params) function.

I replace:

door Door;

with:

door* Door = new door;


and it acts like it's never seen the new operator before.

Somebody help!  :'(
Title: Re: Managed types, arrays, and pointers.
Post by: scotch on Mon 10/12/2007 02:03:31
You're not meant to make managed objects in script, they are for handling internal structs like Characters and Objects, so you can ignore that keyword. You're also not able to take a pointer to a script struct.

The problem with the first bit of code is you also can't use the assignment operator to copy structs, you need to assign each member.

eg

function CreateDoor(this Object*, int WalkToX, int WalkToY, int ToRoomID, int ToRoomX, int ToRoomY)
{
  Doors[TotalDoors].DoorObject = this;
  Doors[TotalDoors].WalkToX = WalkToX;
  ...
}

should compile.
Title: Re: [SOLVED] Managed types, arrays, and pointers.
Post by: Recluse on Tue 11/12/2007 18:59:31
Rawr, thanks for the quick response.