Posts: 780
Threads: 49
Joined: Dec 2001
Does FB support this?
If yes, then I have an error in my code I can't find (I'll post if FB supports this).
If not, then v1c, this is something pretty important you've missed out! Please implement it
Posts: 1,439
Threads: 15
Joined: Apr 2003
What do you mean? This is supported:
Code:
Type T
x As Integer
y As Integer
End Type
Dim Shared Arr(10) As T
Dim i As Integer
For i = 0 To UBound(Arr)
Print Arr(i).x
Next i
Posts: 780
Threads: 49
Joined: Dec 2001
Then I have no idea what is wrong below...
The compiler says that it found ".sX" when it expected "=".
Code:
With Bullet(UBound(Bullet))
'Initial coordinates of the bullet
.sX = Ship.sX
.sY = Ship.sY
.iAlive = 1
'Add the bullet and ship vectors, calculate resultant vector components
sXComp = Ship.sSpeed * Sin(Ship.sHeading) + BULLET_SPEED * Sin(Ship.sFacing)
sYComp = Ship.sSpeed * Cos(Ship.sHeading) + BULLET_SPEED * Cos(Ship.sFacing)
'Calculate speed using with |ai + bj| = Sqr (a^2 + b^2)
.sSpeed = Sqr(sXComp ^ 2 + sYComp ^ 2)
'Calculate the resultant heading
If sYComp > 0 Then .sHeading = Atn(sXComp / sYComp)
If sYComp < 0 Then .sHeading = Atn(sXComp / sYComp) + PI
End With
Posts: 1,439
Threads: 15
Joined: Apr 2003
This compiled fine:
Code:
Type BULLET_T
sX As Single
sY As Single
iAlive As Integer
sSpeed As Single
sHeading As Single
sFacing As Single
End Type
Dim Bullet(100) As BULLET_T
Dim Ship As BULLET_T
With Bullet(UBound(Bullet))
'Initial coordinates of the bullet
.sX = Ship.sX
.sY = Ship.sY
.iAlive = 1
'Add the bullet and ship vectors, calculate resultant vector components
sXComp = Ship.sSpeed * Sin(Ship.sHeading) + BULLET_SPEED * Sin(Ship.sFacing)
sYComp = Ship.sSpeed * Cos(Ship.sHeading) + BULLET_SPEED * Cos(Ship.sFacing)
'Calculate speed using with |ai + bj| = Sqr (a^2 + b^2)
.sSpeed = Sqr(sXComp ^ 2 + sYComp ^ 2)
'Calculate the resultant heading
If sYComp > 0 Then .sHeading = Atn(sXComp / sYComp)
If sYComp < 0 Then .sHeading = Atn(sXComp / sYComp) + PI
End With
Could you post some more context?
Posts: 780
Threads: 49
Joined: Dec 2001
Here is the code:
http://avinash.apeshell.net/stuff/flyaround.bas
I think the problem might be that when I Dim the array, I didn't specify a value inside the brackets, as I don't know how many bullets are on screen...
thanks.
Posts: 1,439
Threads: 15
Joined: Apr 2003
Hrm... that's odd.
Quote:- DIM array(), dynamic arrays with unknown dimensions as in VBDOS/VB (v1c)
That looks to me like it should work...
BTW, I loved Lucky's spaceship thing back in the day.
Posts: 780
Threads: 49
Joined: Dec 2001
v1c...help?
DrV: Yeah, Lucky was a dude...I have old source in VB from what I made using his tuts, which this is part of the port of.
I'm going to rename the title of this thread and add [bug] to it.
Posts: 922
Threads: 15
Joined: Jun 2003
You have to give the full type on that redim preserve, in FB you can create local vars/arrays with same names as global ones (as in C, in QB only arguments could have the same name as globals), that redim preserve is seen as a new array of the last DEF### type, not an UDT.
Posts: 780
Threads: 49
Joined: Dec 2001
Awesome, thanks.
Yeah, this is my VBness coming into play.
Posts: 1,439
Threads: 15
Joined: Apr 2003
Yeah, mine too... that always has tripped me up in QB and now FB. Why couldn't a ReDim without a type be like in VB, referencing the global array? It makes more sense that way to me... Of course, this isn't meant to be compatible with VB in syntax, but the way it is now seems to me to be the source of more bugs than otherwise... just my two cents.