DIMPUSH, I can't use it...

Previous topic - Next topic

ampos

Sorry but I can not get this working...

Code (glbasic) Select

type ball
x
y
dx
dy
endtype

global bola[] as ball

dimpush bola[],0


I always get a compiler error. So I have to use

Code (glbasic) Select
m=bounds(bola[],0)
redim bola[m+1]

Moebius

#1
The second argument of dim push should be a variable to 'push' onto the end of the array.  You're specifying a '0' when the compiler is expecting a variable of the ball type.  If it's expecting a ball, it doesn't know what to do with a 0...

This is what DIMPUSH is meant for:
Code (glbasic) Select
// Add a new ball to the list
LOCAL NewBall AS ball
NewBall.x = 10
NewBall.y = 20
NewBall.dx = 5 //assuming that 'dx' and 'dy' refer to speed as there are no 'vx' and 'vy'
NewBall.dy = 2

DIMPUSH bola[], NewBall


If you just want to use DIMPUSH to extend the array by 1, you would have to use a variable of the type 'ball' like in my short example with all blank values.

Normally if you need to extend the array you will be putting in values anyway, so it's easier to put them in something like 'NewBall' and then 'push' that onto the array, but otherwise you should just do something like what you listed.  I normally do this:
Code (glbasic) Select
REDIM bola[LEN(bola[])+1]
just because it's easier to type, and doesn't need the temporary variable.
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

MrTAToad

You would only do something like :

Code (glbasic) Select
DIMPUSH bola[],0

if bola was a simply integer or floating-point array