Questions about arrays[] and DIMPUSH and DELETE

Previous topic - Next topic

joeb11666

I just got GLBasic; moving on from Emergence Basic(IWBasic now) and I'm converting my half done remake of Cloudburst to GLB. (see my site www.RetroActiveGames.com for what I'm talking about and video progress)
I've seen the Shootemup HOWTO video here and it is extremely helpful. I finally understand TYPES!!! I would suggest to anyone having trouble with GLB just check http://www.glbasic.com/forum/index.php?topic=936.msg4759#msg4759
Anyway...
I really wanted to ask...
How are arrays[] handled when DIMPUSH or DELETE is called?
What happens to an array[1] thru array[5] when DELETE array[3]? Does the array[] shrink? or Position 3 just skipped?

I'm hoping GLB handles it so I don't have to worry about memory and keeping track of what was destroyed. I'm about to add enemies and drops and explosions. See my old example video to see how crazy it gets.

It will also be good to understand how I can limit these instead of having them open ended as in the Shootemup vid.

I'm really liking GLB, I purchased and been programming with it for 2 days, the conversion is going pretty fast.

Now I just need to finish it!

Joe


Ian Price

DIMPUSH "pushes" TYPE data into an array. You don't need to use DIMPUSH with normal arrays - you can just declare them with e.g.

Code (glbasic) Select

DIM array[10]
array[4]=28
array[7]=15
...


DELETE is used to remove TYPEs and their associated data as well as data in an array, but only in a FOR/NEXT loop.

If you want to set an arrays value to zero, then simply use
Code (glbasic) Select
array[x]=0

If you want to delete a cell in array use DIMDEL array[],X. All data following the specified value X will move down.

Look in the helpfiles - they are pretty helpful.

:)

I came. I saw. I played.

Kitty Hello

It's dropping the element from the array, moving the back pieces upwards to fill the gap.
If you don't want the move (usually no big deal), you can move the last item in that place and delete the last item them. The order is not taken care of then, but for shoots and enemies that usually does not matter.

joeb11666

Who reads the instructions to anything? :-[

I was assuming it would be something I wouldn't have to worry about.
Thanks

Ian Price

You don't have to worry about arrays. You don't even have to use them. They can however,  make things a lot simpler if you do understand them and how to use them. And they aren't hard to grasp.

If you need assistance, just shout :)
I came. I saw. I played.

okee

joeb sorry don't mean to hijack your thread but while on the subject of dimpush
could someone post an example of DIMPUSH used with an array of types ?  :nw:
Android: Samsung Galaxy S2 -  ZTE Blade (Orange San Francisco) - Ainol Novo 7 Aurora 2
IOS: 2 x Ipod Touch (1G)

MrTAToad

Something like this (which pushes one item into the array and displays its value) :

Code (glbasic) Select
TYPE tArray
a%
ENDTYPE

GLOBAL array[] AS tArray
LOCAL toPush AS tArray

DIM array[0]

toPush.a%=12
DIMPUSH array[],toPush

DEBUG "Value : "+array[0].a%+"\n"

okee

MrTAToad

Yeah, that makes sense, Thanks

okee
Android: Samsung Galaxy S2 -  ZTE Blade (Orange San Francisco) - Ainol Novo 7 Aurora 2
IOS: 2 x Ipod Touch (1G)