Global TYPEs

Blitz3D Forums/Blitz3D Programming/Global TYPEs

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Yep, that's entirely possible. Types are global, but to get to a specific type instance, you must use either it's handle or give it an ID, unless you want to mess about with the Object() and Handle() commands.

Something like this should work:
TYPE Ship 
  Field id
  Field X 
  Field Y 
END TYPE

ImAShip = CreateShip()
ImAnotherShip = CreateShip()

MoveShip(ImAShip,5,10)
MoveShip(ImAnotherShip,100,24006583)

Function CreateShip()
   Ship.Ship = Last Ship
   If Ship = Null
      id = 1
   Else
      id = Ship\id + 1
   End If
   Ship.Ship = New Ship
   Ship\id = id
   Return id
End Function

Function MoveShip(id,movex,movey)
  For Ship.Ship = Each Ship
    If Ship\id = id
       Ship\x = Ship\x + movex
       Ship\y = Ship\y + movey
    End If
  Next
End Function


You can do the same with Handle and Object, but they are a little more tricky. Try searching the forums for them, to see how they are used.

Fredborg