Global TYPEs

Blitz3D Forums/Blitz3D Programming/Global TYPEs

You don't even need ID values if you don't want. If you have a certain type that you want to be global throughout the program, just create a Global Type Pointer like the following re-write of FredBorg's code:

TYPE Ship 
  Field X 
  Field Y 
END TYPE

Global ImAShip.Ship = CreateShip()             ;<------ GLOBAL
Global ImAnotherShip.Ship = CreateShip(10,10)  ;<------ GLOBAL

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

Function CreateShip.ship(x=0, y=0)
     ; Create a LOCAL Ship pointer and assign its
     ; values. Then return the value of the Ship type pointer
     ; To whatever called the function..
   ThisShip.Ship = New Ship
   ThisShip\x = X
   ThisShip\y = Y
   Return ThisShip
End Function

Function MoveShip(thisship.ship, movex, movey)
   ThisShip\x = ThisShip\x + movex
   ThisShip\y = ThisShip\y + movey
End Function


You could also use an array of Ship pointers. Types are VERY flexible!! :D :D :D

Wiebo: Well, the types themselves ARE global. (That is, the list of types themselves. And it's for this reason you can create "preserved redimensional arrays" of types...) But when you create a type POINTER, it is local by default.

eg bad.baddy = New baddy <--- "bad" is a local pointer to a new baddy. The baddy is global until you delete it, but "bad" will lose the value of the baddy it's pointing to when you leave a function, unless you specify it as being a global pointer variable.