Another Type Question
Blitz3D Forums/Blitz3D Beginners Area/Another Type Question
| ||
I am not sure if it is possible. I have Two Types Type A Field X,Y End Type Type B Field X,Y End Type Repeat If Rand(0,1)=1 UpdateFunction(TypeA) Else UpdateFunction(TypeB) End if Function UpdateFunction(Type) There is a camera Function in here that I want to react to which ever type is used. one Type is a Ship the other a Person. Kinda like I want to pass the Active entity to the camera routine. End Function Is it possible to pass the type into a function, and within the function have access to all the fields. |
| ||
You can pass across the type pointer:Type thing field x,y End Type t.thing = new thing do_stuff(t.thing) function do_stuff(t.thing) t\x = t\x +1 end function |
| ||
Ross I Understand that but using your code Can I do the following. Type thingA field x,y End Type Type thingB field x,y End Type TA.thingA = new thingA TB.thingA = new thingA If This=True do_stuff(TA.thingA) Else do_stuff(TB.thingB) End if What can I do below??? function do_stuff(t.thing) t\x = t\x +1 end function Regards, Eric |
| ||
The first part of your type point can be anything u want. BUT the part after the dot, must be the actual type name. [CODE] Type thingA field x,y End Type Type thingB field x,y End Type TA.thingA = new thingA TB.thingA = new thingA [/code] But, why have two type collections, which contain the same data? why not do... [CODE] Type thingA field x,y End Type TA.thingA = new thingA TB.thingA = new thingA [/code] then If This=True do_stuff(TA.thingA) Else do_stuff(TB.thingA) End if function do_stuff(t.thingA) t\x = t\x +1 end function TB.thingA and TA.thingA are different type objects, using the type collection "thingA" |
| ||
"But, why have two type collections, which contain the same data? why not do... " Because One type is a Ship and the other is a Human. I guess I didn't have to use types because there is only one of Each. But I like how Types work and I don't have to declare each Variable as Global. My Function is a camera Routine and I want to pass to it the Entity that is Active. I have it working with some if then statements, but I wanted to streamline it. Regards, Eric Type Man Field O2 Field Health Field X#,Y#,Z# Field VX#,VY#,VZ# Field Entity Field Center Field RB End Type Type Ship Field X#,Y#,Z# Field XV#,YV#,ZV# Field Altitude Field Speed Field Fuel# Field RB Field Entity Field Pilot Field Center Field Landed Field ThrustSound End Type |
| ||
Ah, sorry, i thought both types contained the same data :) |
| ||
here is one way to do itType CommonFields Field X#,Y#,Z# Field VX#,VY#,VZ# Field Entity Field RB Field Center End Type Type Man Field CommonFields.CommonFields Field O2 Field Health End Type Type Ship Field CommonFields.CommonFields Field Speed Field Fuel# Field Pilot Field Landed Field ThrustSound End Type SomeMan=New man SomeMan\CommonFields=New CommonFields SomeMan\CommonFields\x=100 Repeat If Rand(0,1)=1 UpdateFunction(SomeMan\CommonFields) Else UpdateFunction(SomeShip\CommonFields) End If Function UpdateFunction(CommonFields.CommonFields) PointEntity camera,CommonFields\entity Print CommonFields\x ;etc. |
| ||
here is another wayType Thing Field X#,Y#,Z# Field VX#,VY#,VZ# Field Entity Field RB Field Center Field Man.Man Field Ship.Ship End Type Type ManFields Field O2 Field Health End Type Type ShipFields Field Speed Field Fuel# Field Pilot Field Landed Field ThrustSound End Type Joe.Thing=New Thing Joe\ManFields=New ManFields Joe\ManFields\Health=45 Joe\Entity=CreateCube() Voyager.Thing=New Thing Voyager\ShipFields=New ShipFields Voyager\ShipFields\Feul=12.6 Voyager\Entity=CreateCone() Repeat ;Update Ships For Thing.Thing=New Thing ;Update Ships only right now If Thing\ShipFields<>Null Then MoveEntity Thing\Entity, Thing\VX...... UpdateFunction(Thing) EndIf Next Function UpdateFunction(Thing.Thing) PointEntity camera,Thing\Entity Print Thing\x ;etc. |
| ||
Hey thanks for the Ideas and Code, I will try them on when I get home from work... Again, Thanks. Eric |
| ||
I just thought I would post and say that your Use of Types worked like a charm.. It was exactly what I was looking for. Thanks Again, Eric |