Type problem.
Blitz3D Forums/Blitz3D Programming/Type problem.
| ||
Hi I have until now used different types for players,enemies,objects etc.. no problem.. But now i tried to use one Type class for different "objects". Example. The only difference in the sample below is that one object is a cube and the other one is a ball. But why does the ball rotate ??? When i do a "For cube.entity = Each entity" dont it just check the cube.entity "class" ?? [CODE] Graphics3D 1024,768,32,2 SetBuffer BackBuffer() Type Entity Field Name$ Field Model Field RX#,RY#,RZ# End Type camera = CreateCamera() light = CreateLight() setup() PositionEntity camera,0,0,-20 ;Main Loop While Not KeyHit(1) update_all() UpdateWorld RenderWorld Flip Wend End Function setup() Cube.Entity=New Entity Cube\name = "Cube" Cube\model = CreateCube() Cube\RX#=Rand(-3,3) Cube\RY#=Rand(-3,3) Cube\RZ#=Rand(-3,3) PositionEntity Cube\model,-10,0,0 Ball.Entity=New Entity Ball\name = "Ball" Ball\model = CreateSphere() Ball\RX#=Rand(-3,3) Ball\RY#=Rand(-3,3) Ball\RZ#=Rand(-3,3) PositionEntity ball\model,10,0,0 End Function Function update_all() For cube.entity = Each entity TurnEntity Cube\model,Cube\rX#,Cube\ry#,Cube\rz# Next End Function |
| ||
When i do a "For cube.entity = Each entity" dont it just check the cube.entity "class" ?? No, you'll have to do that yourself. A For/Each loop iterates through every object in the list. |
| ||
cube.entity = new entity sphere.entity = new entity For banana.entity = each entity count = count + 1 Next Print count RESULT = 2 Const TCUBE = 1 Const TSPHERE = 2 cube.entity = new entity : cube\eType = TCUBE sphere.entity = new entity : sphere\eType = TSPHERE For banana.entity = each entity If banana\eType = TCUBE count = count + 1 EndIf Next Print count RESULT = 1 |
| ||
Yes, i have solved with an if statement.. But i thought i did something wrong. Thanks guys. |