Types
Blitz3D Forums/Blitz3D Beginners Area/Types
| ||
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? |
| ||
Try thisType 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... |
| ||
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 |
| ||
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 [] |
| ||
Thanks Tric, Any time ;) |
| ||
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. |
| ||
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) :) |
| ||
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 |