Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[BUG] Array Of Types
#1
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 Big Grin
·~¹'°¨°'¹i|¡~æthérFòx~¡|i¹'°¨°'¹~·-
avinash.vora - http://www.avinashv.net
Reply
#2
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
Reply
#3
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
·~¹'°¨°'¹i|¡~æthérFòx~¡|i¹'°¨°'¹~·-
avinash.vora - http://www.avinashv.net
Reply
#4
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?
Reply
#5
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.
·~¹'°¨°'¹i|¡~æthérFòx~¡|i¹'°¨°'¹~·-
avinash.vora - http://www.avinashv.net
Reply
#6
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. Smile
Reply
#7
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.
·~¹'°¨°'¹i|¡~æthérFòx~¡|i¹'°¨°'¹~·-
avinash.vora - http://www.avinashv.net
Reply
#8
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.
Reply
#9
Awesome, thanks.

Yeah, this is my VBness coming into play.
·~¹'°¨°'¹i|¡~æthérFòx~¡|i¹'°¨°'¹~·-
avinash.vora - http://www.avinashv.net
Reply
#10
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)