types within types
Blitz3D Forums/Blitz3D Programming/types within types
| ||
i bet this question has been asked a million times but i need to know the answer. how do you put types in types? can someone give me a quick example on how to pull this off? |
| ||
You can't do that, the language doesn't support it. Unless I'm not understanding what you mean. Could you elaborate? |
| ||
Yes you can: It is sort of like this: Set up the first Type. Create the second Type, however, include a field that references the first Type. So you might have a Type for Orc with fields of race, level, money, etc. which is called 'Orc' - in the second Type called MageOrc you could have a field called MOrc - which includes the Orc Type into the new MageOrc (MOrc.Orc), plus any new fields for MageOrc such as magic, spell_level, etc. I sort of did that out of my head - but that is the general idea. |
| ||
. |
| ||
. |
| ||
YES you can, here's a good example from Krylar's book "Learn to Program 2D Games in Blitz Basic"... Quote: Type Ships Field Name$ Field LaserPower% Field Armor% Field ShieldPower% Field Missiles% Field TopSpeed% End Type Type Destroyers Field ShipBasics.Ships Field LandingBays% Field FighterCompliment% Field IonCannonPower% End Type Destroyer\ShipBasics.Ships = New Ships Destroyer\ShipBasics\Name$ = Name$ Destroyer\ShipBasics\LaserPower% = LaserPower% ... ... Destroyer\LandingBays% = LandingBays% Hope this helps IPete2. |
| ||
Cripes - he must have got excited. |
| ||
Is this what you meanType efx Field sprite Field x# Field y# Field z# Field angX# Field angY# Field angZ# Field alpha# Field gravity# Field life# Field Scale# End Type Type PProj Field entity Field OldX# Field OldY# Field OldZ# Field XVel# Field YVel# Field Power# Field range# Field facing Field Life# Field spritecount Field sprites.efx[40] ;array of types in type note the square brackets Field SpriteIndex Field explode Field HitPlayer Field HitEntity Field Delay# End Type ;Player Type P Field Entity Field X# Field Y# Field Z# Field OldX# Field OldY# Field OldZ# Field XVelocity# Field YVelocity# Field ZVelocity# Field YRot# Field Facing Field Falling Field action Field OldAction Field MoverOffset# Field MoverZOffset# Field jumpoff# Field OKToJUMP Field index Field layer Field OldIndex Field OldLayer Field PProjectile.PProj ;Type in type with type in that type Field Health Field Score Field OldScore Field Lives Field Magic Field MagicTimer# Field shadow Field Rshadow Field Lshadow Field SUshadow Field RSUshadow Field LSUshadow Field SSUshadow Field RSSUshadow Field LSSUshadow Field SSDshadow Field RSSDshadow Field LSSDshadow Field SDshadow Field RSDshadow Field LSDshadow Field Fshadow Field Bshadow Field BlockStub Field shadowtexture Field Playerhealth Field PlayerScore[5] Field PlayerLives Field PlayerMagic Field MagicTex Field healthTex Field LivesTex Field ScoreTex[5] Field ResetX# Field ResetY# Field ResetZ# Field GoldKey Field GoldKeySprite Field GoldKeyTex Field RedKey Field RedKeySprite Field RedKeyTex Field BlueKey Field BlueKeySprite Field BlueKeyTex Field WhiteKey Field WhiteKeySprite Field WhiteKeyTex Field BlackKey Field BlackKeySprite Field BlackKeyTex Field Anim_Idle Field Anim_Run Field Anim_Shoot Field Anim_Jump Field Anim_Shoot_Run Field PlayerLight Field Pivot Field Textbox Field Textbox1 Field Textbox2 Field TextboxSprite Field TextboxFont Field EMFootDust End Type |
| ||
He's showing off - it doesn't count. |
| ||
You can also referrence a type within itself as I'm usingType vector Field x Field y Field z End Type Type object Field pos.vector Field siz.vector Field rot.vector Field next_obj.object Field prev_obj.object End Type Just remember that you need to create new instance of all subtypes. eg. To create an object I would need to use... Object1.object=New object Object1\pos=New vector Object1\siz=New vector Object1\rot=New vector ...to create vectors for position, size and object. |
| ||
thank you so much! *skyfire1 jumps around his room. *skyfire1 says like he's jumping around the room but in reality, he's sitting on his chair, doing absolutly nothing. |
| ||
Warren, what were you referring to? =] |