hello.
I made a function that would create an ai for an RTS I'm working on. I Store all the Ai data in one array, to keep it simple and dynamic I made a function that would expand the array every time I made a new unit by coping the data from the main array to a place holder of equal size. I then undim and then re dim the main array plus one slot. It seems to work fine in terms of data storage. But the AI don't work right.
1: only the first unit to be made actually spawns on the map. all the others are nowhere to be seen.
2: for debug I print all the x positions of the objects just to see what it says. the first unit, prints it's location fine. But all the other units have "-1.#IND". I'm not sure what this means.
3: if I spawn a unit object but don't add it to the AI system, it works just fine. it's weird because it used to always work, but then one time when I compiled it did it like I described. and no amount of back stepping seems to fix it.
This is the code that calls the spawn unit function.
for a = 1 to 20
makeleader(1,1)
next a
Code that makes the unit.
function makeleader(team,major)`====================================================================
`expand ai array by one
number = expandaiarray()
`load player object
num = findfreenum()
make object box num,20,50,20
`fill array
ai(number,0) = team `team number
ai(number,1) = major `if the commander created is the players, give it derect functions
ai(number,2) = 1 `unit type, 1 for commander
ai(number,3) = num `object number
ai(number,4) = 0 `selected
ai(number,5) = playerdata(0,3)
inc playerdata(0,3),1
`position player at base
position object num,object position x(objectsonmap(0)),object position y(objectsonmap(0)),object position z(objectsonmap(0))
ai add enemy num ` add to ai system <--- if I comment this out the objects place normally
` AI SET ENTITY SPEED num,60
`color object to team
a = 0
repeat
if ai(number,0) = playerdata(a,0)
`apply color
if playerdata(a,1) = 1 `red
color object num,RGB(255,0,0)
endif
if playerdata(a,1) = 2 `blue
color object num,RGB(0,0,255)
endif
if playerdata(a,1) = 3 `teal
color object num,RGB(0,160,192)
endif
if playerdata(a,1) = 4 `purple
color object num,RGB(255,0,255)
endif
a = -1
else `if not the slot go again
inc a,1
endif ` ai(slot,0) = playerdata(a,0)
UNTIL a = -1
ENDFUNCTION
And this is the code that expands the array by one.
function expandaiarray()
number = ai(0,0)
`if number is zero then do something else
if number = 0
dim hold(0,aislots)
hold(0,0) = ai(0,0)
hold(0,1) = ai(0,1)
hold(0,2) = ai(0,2)
hold(0,3) = ai(0,3)
hold(0,4) = ai(0,4)
hold(0,5) = ai(0,5)
undim ai()
dim ai(1,aislots)
ai(0,0) = 1
ai(0,1) = hold(0,1)
ai(0,2) = hold(0,2)
ai(0,3) = hold(0,3)
ai(0,4) = hold(0,4)
ai(0,5) = hold(0,5)
undim hold()
print "ai ",ai(1,3)
sync
sleep 200
number = 1
else `if number = 0
`make array to hold all ai data
dim hold(number,aislots)
`copy data`
for a = 1 to number
hold(a,0) = ai(a,0)
hold(a,1) = ai(a,1)
hold(a,2) = ai(a,2)
hold(a,3) = ai(a,3)
hold(a,4) = ai(a,4)
hold(a,5) = ai(a,5)
next a
undim ai()
dim ai(number+1,aislots)
ai(0,0) = number + 1
for a = 1 to number
ai(a,0) = hold(a,0)
ai(a,1) = hold(a,1)
ai(a,2) = hold(a,2)
ai(a,3) = hold(a,3)
ai(a,4) = hold(a,4)
ai(a,5) = hold(a,5)
NEXT a
undim hold()
inc number,1
endif `if number = 0
ENDFUNCTION number
Thanks for the help.