@Alien Menace:
Ah, I see what you want to do. Well, storing enormous amounts of information in arrays (often with 1000s of objects) is something I do in pretty much every single program I write. One thing you have to remember with both DarkBASIC Professional and the AppGameKit is that neither of them are really Object Oriented languages.
Here's how I would achieve what you need to do:
global bulletcount=0 //for some reason, in AGK there is no function to automatically retrieve the size of an array like in DBPro
type bulletinfo //it's a habit of mine to always use all lowercase and also to always put "info" on the end of a type name
exist as integer
status as integer
sprite as integer
x# as float //you don't actually need the # but if these are going to be floats it makes it easier to recognise them
y# as float
speedx# as float //I always specify what type a variable is, but if they're all integers then it's not necessary
speedy# as float
endtype
dim bullet[0] as bulletinfo //if this were DBPro, you would use (0) rather than [0]
do
if getrawkeypressed(32)=1 //spacebar
index=addbulletindex() //if there's a free space in the array, it'll use that, otherwise it'll expand the array
bullet[index].exist=1
bullet[index].sprite=createsprite(25)
bullet[index].x#=getspritex(playership)
bullet[index].y#=getspritey(playership)
bullet[index].speedx#=0
bullet[index].speedy#=-1
bullet[index].status=1
endif
for i=0 to bulletcount-1
if bullet[i].y#<0
bullet[i].status=0
else
bullet[i].x#=bullet[i].x#+bullet[i].speedx# //you should probably use getspritex(bullet[i].sprite) to save on memory
bullet[i].y#=bullet[i].y#+bullet[i].speedy#
setspriteposition(bullet[i].sprite,bullet[i].x#,bullet[i].y#)
endif
if bullet[i].status=0 then bullet[i].exist=0 //now it will simply be overwritten next time you need a new bullet
next i
sync()
loop
function addbulletindex()
index=-1
for i=0 to bulletcount-1 //hopefully, if TGC hasn't broken AGK recently, when bulletcount=0, this loop should not start
if bullet[i].exist=0
index=i
exit //leave the for-next loop early
endif
next i
if index=-1 //there was no unused array index
bulletcount=bulletcount+1
dim bullet[bulletcount] as bulletinfo
index=bulletcount-1 //as far as I know, AGK arrays are 0-based
endif
endfunction -1
I'm sure you noticed the much larger code and groaned. There ARE ways of making the code smaller, but it's almost always far less efficient in terms of speed and memory use. However, it IS still quite easy to add new types. You said you sometimes have dozens of types, so I've set the code up in a way that makes it easy to add new types. Just copy-paste the addbulletindex() function and replace all "bullet" with the new type name, dim the new array at the top of the code.
In theory this code will execute faster than a dynamic list system when adding and removing lots of items, because items in memory are not even being shifted down, they are simply not being moved at all. The worst-case scenario would be to add thousands of elements, then remove almost all of them, leaving only some at the end. In that case, since you are not actually removing unused elements (just marking them as exist=0 and leaving them there), you would be iterating over thousands of unused elements just to find the used ones at the end.
With this system, you must remember to initialise new elements to some value. They will sometimes still contain values from when the element was previously used, and this can cause confusing bugs. Don't assume values will be 0, initialise them. Alternatively you could modify the code so when you delete an element, as well as setting exist to 0, you also set all other values in the type back to 0 or "".
This system works well for lots and lots of objects that are added and removed frequently.
It just occurred to me that you might be concerned about allocating new memory with every single bullet (until you reach the point where bullets are being deleted fast enough to not need to expand the array, of course - maybe you hadn't even thought of this, I don't know). Well, there's a very easy way around this too. You just allocate additional memory in blocks (like lists in C++):
function addbulletindex()
index=-1
for i=0 to bulletcount-1 //hopefully, if TGC hasn't broken AGK recently, when bulletcount=0, this loop should not start
if bullet[i].exist=0
index=i
exit //leave the loop early
endif
next i
if index=-1 //there was no unused array index
bulletcount=bulletcount+100
dim bullet[bulletcount] as bulletinfo
index=bulletcount-100 //as far as I know, AGK arrays are 0-based
endif
endfunction -1
Anyway, I have an episode of Spooks (on DVD) to go watch, so if I missed something or forgot something or if that code doesn't actually work (I'm pretty sure it's right, but I didn't test it), don't hesitate to ask me about anything. And really, that's the easiest and quickest way of using arrays with gazillions of bullets. I'm sorry I couldn't make it any simpler for you, I can understand how annoying it is that AppGameKit doesn't have easy OO programming methods.
Clonkex