Array of Type

Blitz3D Forums/Blitz3D Programming/Array of Type

This is a confusing subject for me, and i'm sure it has already been asnwered somewhere but here goes...

I have written a pathfinding routine for my Paradise Island game which creates a path in the following datatype

type AIpath
field x,z
end Type

This works fine except I want to have multiple units in the game all recording their own path, so I dimensioned a pointer for the datatype

dim path(unitQty).AIpath

The problem is that path().AIpath stores a pointer to the entire AIpath stack, rather than creating individual stacks for each unit.

Is there a way to dimension the data type itself? ie:

type AIpath(unitQty)
field x,z
end type

Dim Path(num).AIpath

Path(1) = New AIpath
Path(1)\X = 12

You should then always be able to refernece unit (1) by using

X = Path(1)\X

Does that help?

Rhy :)

The above should be .. Dim Path.AIpath( num )

Stevie

When I try that Stevie G I need to find the syntax that works for commands like this:

path.aiPath(id)=Last aiPath(id)

If I do

path.aiPath(id)=last aiPath

then surely i'm getting the last aiPath in memory arn't I? Which probably isn't the last path entry for the specific unit i'm seeking.

Blitz doesn't natively let you create separate lists of the same type - I believe BMax does, though. However, this is easily solved by implementing your own separate linked lists of types.

Given your example, you would first need to expand the aiPath type:
Type aiPath
  Field x,y
  Field link.aiPath
End Type


Now create an array to hold the pointers to each individual linked list:
Dim path.aiPath(unitQty)


Now, create a new instance and add it to 'player1' linked list:
point.aiPath = New aiPath
point\x = blah
point\y = blah
point\link = path(player1)
path(player1) = point


To iterate through player1's entire path:
point.aiPath = path(player1)
While point <> Null
  ; Do stuff with this point here.

  ; Get next point in linked list.
  point = point\link
Wend


Well, that's the basic idea, anyway. :)

Also, have a look at my post in this thread for a similar method except it implements the working of an actual stack:
http://www.blitzbasic.com/Community/posts.php?topic=48442#539401

Thank you, it's as I feared :(

My implementation may allow me to use coded breaks which should be a bit faster in runtime but before I try to get that working i'm going to have a look at the pathfinding algorythm, if I can make it store less waypoints for each path I may just set up a small array for each unit.