Damn these types!!
Blitz3D Forums/Blitz3D Beginners Area/Damn these types!!
| ||
For the love of God, someone please tell me what is going on. I have a type -> Particles Type Particles Field x#, y#, z# Field xdelta#, ydelta#, zdelta# Field image End Type Now, I create an instance of the type: snow ; Snow Global snow.Particles Global snowspriteimage = LoadSprite("snow.bmp",15); For j=1 To 100 snow.Particles = New Particles snow\x# = Rand(-50, 10); snow\y# = 50; snow\z# = Rand(75, -75) snow\xdelta# = Rnd(-0.2, 0.2) snow\ydelta# = -0.1 + Rnd(-1.0) snow\zdelta# = -0.1+Rnd(-0.1, 0.01) snow\image = CopyEntity(snowspriteimage) SpriteViewMode snow\image, 1 RotateEntity(snow\image, 90 , 0 , 0) PositionEntity snow\image, snow\x, snow\y, snow\z EntityColor snow\image, 255,0,0 Next now how do I create two or more instances of this type without referencing the first instance -> snow? Thanks in advance! |
| ||
1) You don't need to end a line of code with a semi-colon. 2) You may be using old and incorrect type documentation. Download the newest docs (1.83) (and update the compiler too, if you haven't). You have just created 100 instances of the Particles type. The most recently created instance is referenced by the variable 'snow'. To create two more instances, you can do either of the following: a) change 'For j=1 To 100' to 'For j=1 To 102' b) Add 'snow = New Particles' twice to the end of the program (or use any variable name you wish). All instances of the same type are in a linked list 'behind the scenes.' |
| ||
if you want to refer to any in particular you'll have to set up an array like so:parts.particles(100) for i=0 to 100 parts(i)=new particles next ; now you can go: o.particles=parts(5) |
| ||
You don't really need to make "snow" global. The 100 type objects you're creating are being created, then dereferenced, but they still exist. You can still step through all the particles you've created if they don't have independant variables referencing them, like at the bottom here: Type Particles Field x#, y#, z# Field xdelta#, ydelta#, zdelta# Field image End Type Global snowspriteimage = LoadSprite("snow.bmp",15); hideentity(snowspriteimage) ; <== Hide the sprite you just loaded -- it's going to stay put For j=1 To 100 snow.Particles = New Particles snow\x# = Rand(-50, 10); snow\y# = 50; snow\z# = Rand(75, -75) snow\xdelta# = Rnd(-0.2, 0.2) snow\ydelta# = -0.1 + Rnd(-1.0) snow\zdelta# = -0.1+Rnd(-0.1, 0.01) snow\image = CopyEntity(snowspriteimage) SpriteViewMode snow\image, 1 RotateEntity(snow\image, 90 , 0 , 0) PositionEntity snow\image, snow\x, snow\y, snow\z EntityColor snow\image, 255,0,0 Next While (1) For particle.Particles = Each Particles TranslateEntity(particle\image, particle\xdelta, particle\ydelta, particle\zdelta) Next UpdateWorld() RenderWorld() Flip() Wend |