Types

Blitz3D Forums/Blitz3D Beginners Area/Types

syfax(Posted 2003) [#1]
OK, the first of many Qs here I think. The Types are different to what I've used before and are confusing me.

I have a jet and I give it a weapon. Both the jet and weapons have types. How do I directly read, say, the power of the weapon.

I've got this far:

Type jet
Field entity
Field weapon
End Type

Type weapon
Field id
Field power
End Type

fighter.jet = New jet
fighter\weapon=1
laser.weapon=New weapon
laser\power=10

;Print fighter's weapon


I've been trying things like fighter\a.weapon=New weapon

Thanks, sorry for being such a newbie :)

PS how do I get code I paste in in green?


Tricky(Posted 2003) [#2]
Try this
Type Weapon
Field id
Field power
End Type

Type jet
Field entity
Field weapon.weapon
End Type


On that way fighter\weapon.weapon = New Weapon could work...
If THAT is the question...


syfax(Posted 2003) [#3]
Thanks Tric, Types are starting to make sense now :)

This is what I was tring to make btw:

Type weapon
Field id
Field power
End Type

Type jet
Field entity
Field weapon.weapon
End Type

laser.weapon=New weapon
laser\power=10

fighter.jet=New jet
fighter\weapon = laser.weapon

Print fighter\weapon\power


Michael Reitzenstein(Posted 2003) [#4]
That's the way I have done weapons in all of my games.

To put code into the green and black text, simply do something like this:

{code}
blah
{/code}

and replace the {} with []


Tricky(Posted 2003) [#5]
Thanks Tric,

Any time ;)


Who was John Galt?(Posted 2003) [#6]
syfax-
Very minor point- you could just say

fighter\weapon=laser

as laser has already been declared as type weapon. Saves a bit of typing, but you might argue it doesn't make the code so clear. Matter of preference, s'pose.


syfax(Posted 2003) [#7]
Thanks all

0DFEx, I think I'll leave it the way I had it until I get my head round types a bit better. It is clearer this way (and things need to be very very clear to make sense to me) :)


Who was John Galt?(Posted 2003) [#8]
Yeah sure, know what u mean, syfax! I took me a while reading around to understand it. There's some good stuff on www.blitcoder.com on types, too, but I think you're there. Main thing to remember is that if you create a new instance of a type (laser1.laser=new laser),all it returns is a handle to laser 1, which is a number Blitz uses to access the data associated with that object. Also useful is repeated use of \ to go into types 'within' types, eg: You get a laser power-up...
fighter\weapon\power=fighter\weapon\power+1