Accessing the Fields of a Type If all you know is
BlitzMax Forums/BlitzMax Programming/Accessing the Fields of a Type If all you know is
| ||
Accessing the Fields of a Type If all you know is another field from the Type.
Type TShip
Field Ship:TModel
Field Altitude:Float
Function Create:TShip()
Temp:Tship = New TShip
Temp.Ship = LoadModel("Test")
End Funtion
End Type
If I am Passing Temp.Ship to a function and I need to Derive the Altitude Field... How would I go about that? Function ModelColide(Temp:TModel) <---- I can't pass a TShip here How to I derive the "TYPE" that Temp:TModel Belongs to so that I can Access the Altitude Field? End Funtion Thanks for any help, Eric |
| ||
| It seems to me that if you rely on altitude in the ModelCollide function, then you should probably shift the altitude property to the model class. Failing that, implement a collide check in the ship and invoke that instead. Last edited 2010 |
| ||
| I'm guessing you have several game types eg; "TShip", "TMissile". Each may be on a separate altitude and you want to check for collisions between them (maybe?). One way would be to have a base "TModelObject" base class and derive the specific types from it.. Type TGameObject Field model:TModel Field Altitude:Float Method Collides:Int ( Other:TGameObject ) Return Altitude = Other.Altitude End Method End Type Type TShip Extends TGameObject End Type Type TMissile Extends TGameObject End Type Local ship:TShip = New TShip Local missile:TMissile = New TMissile ' simple collision check Print missile.Collides( ship ) Since you cannot access fields in the way you were hoping, maybe a simpler answer would be to pass the altitude to the collide function... Function Collides:Int ( a:TModel, altitudeA:Float, b:TModel altitudeB:Float ) End function Just throwing some ideas in. Last edited 2010 |
| ||
| Hey thanks for the great responses..MAtibee... I guess it's time for a little design work. Regards, Eric |
| ||
Type TShip Extends TModel
Field Altitude:Float
End Type
Function ModelColide(Temp:TModel)
if Tship(temp) then
print TShip(Temp).altitude
else
print "this is not a ship!"
end if
End Funtion
Last edited 2010 |
| ||
| Never mind, just realised this is the Bmax forum :( Last edited 2010 |
| ||
| Slotman, I wouldn't recommend that solution above Matibee. The casting and special case seems inelegant and hard to make generic for different objects colliding. |