[SOLVED] Managed types, arrays, and pointers.

Started by Recluse, Mon 10/12/2007 01:51:27

Previous topic - Next topic

Recluse

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:

Code: ags
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.

Code: ags
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.

Code: ags
I replace:

door Door;

with:

door* Door = new door;


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

Somebody help!  :'(
All your verbcoin are belong to us.

scotch

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
Code: ags

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

should compile.

Recluse

All your verbcoin are belong to us.

SMF spam blocked by CleanTalk