I have been developing(hacking script) a factory type scene where I have a machine that makes balls that fall onto a conveyor belt. These balls then move down the convyor belt. What I am trying to figure out now is how to have each individual Ball moved from the first conveyor to another conveyor by a mechanical arm. Each ball is a type Ball with various fields for positioning and movement the ball instances. When instances of my type ball collides with specific surafces (e.g. the conveyor) the ball instance moves in a new direction. To get instances of the ball to move in synch with the grabbing "hand" of the mechanical arm I thought I would get the EntityX(),EntityY(),EntityZ() and apply it to the x,y,z fields of the each Ball instances. However when I set this up and run it as soon as the Ball entity makes contact with the hand of the mechanical arm I get a memory access violation error. As I am new to Blitz script (epeecially fields and instances) could someone tell me if I am thinking about this right here are the relvent code snippets muh of which I hackd togther from Blitz samples:
Const CT_BALL = 1 Const CT_PLANE = 2 Const CT_ARM = 5 ;I have changed the response to see if that did anything ;and did not Collisions CT_BALL , CT_PLANE , 2 , 2 Collisions CT_BALL , CT_ARM , 2 , 0 Type Ball Field Entity Field x# , y# , z# Field xs# , ys# , zs# End Type ;----------------------------- ;---- conveyor belt --------- ;----------------------------- conv1=LoadMesh("conveyor1.b3d") EntityType(conv1 , CT_PLANE) ;------------------------------- ;---------- ARM STUFF ---------- ;------------------------------- base2=LoadMesh("arm_base.b3d") ScaleEntity base2,.33,.33,.33 ;MoveEntity base2,6.5,26,80 PositionEntity base2,-5,26,94 ;RotateMesh base2,-30,0,0 RotateEntity base2,0,90,30 arm2=LoadMesh("arm_part.b3d",base2) MoveEntity arm2,0,3,0 ScaleEntity arm2,.5,.5,.5 for_arm2=LoadMesh("arm_part.b3d",arm2) MoveEntity for_arm2,0,40,0 catcher = CreateCube(for_arm2) ScaleEntity catcher,10,30,30 PositionEntity catcher,0,40,0 EntityType(catcher , CT_ARM) Repeat ;------------------------------------------ ;------------- arm animation stuff--------- ;------------------------------------------ Angle = Angle + 2 negAngle = negAngle - 2 If Angle > 359 Then Angle = 0 : negAngle = 0 RotateEntity arm,Sin(angle) * 60,0,0 RotateEntity for_arm,Sin(angle) * 60,0,0 RotateEntity arm2,Sin(negAngle) * 60,0,0 RotateEntity for_arm2,Sin(negAngle) * 60,0,0 RotateEntity arm3,Sin(angle) * 60,0,0 RotateEntity for_arm3,Sin(angle) * 60,0,0 ;------------------------------------------ ;----- the next lines of code create ;----- and updates instances of Type Ball ;------------------------------------------ frame=MilliSecs()/100 Mod 7 frame2=MilliSecs()/100 Mod 9 UpdateBalls(0.025) ;----- Everytime the timer ticks at 1 or less create a ball ---- frame=MilliSecs()/.1 Mod 200 If (frame <1) CreateBall() EndIf UpdateWorld RenderWorld Flip Until KeyHit (1) End Function UpdateBalls(Gravity#) For instance.Ball = Each Ball If Not instance = Null instance\x# = instance\x# + instance\xs# instance\z# = instance\z# + instance\zs# instance\ys# = instance\ys# - Gravity# instance\y# = instance\y# + instance\ys# ;If the ball collides with he conveyour move down the conveyor If EntityCollided(instance\Entity , CT_PLANE) instance\ys# = Abs(instance\ys# / 1.08) instance\zs# = .15 EndIf ;------------------------------------------------------------------------ ;---------- when the mechanical arm/hand touches ---------------- ;---------- the ball move the ball with the hand ---------------- ;---------- THIS IS THE PART THAT DOES NOT WANT TO WORK ---------------- ;------------------------------------------------------------------------ If EntityCollided(instance\Entity , CT_ARM) instance\ys# = EntityX( entity, globalFlag ) EndIf PositionEntity(instance\Entity , instance\x# , instance\y# , instance\z#) ;this deletes the instances when it has reached y = -10 If instance\y# < -10 FreeEntity instance\Entity Delete instance EndIf EndIf Next End Function Function CreateBall() Ball.Ball = New Ball Ball\Entity = LoadMesh("glob.3DS") EntityType(Ball\Entity , CT_BALL) ScaleEntity(Ball\Entity , .1 , .1 , .1) EntityRadius(Ball\Entity , .15) ;initial position of the Balls Ball\x# = 6.1 Ball\y# = 4.8 Ball\z# = 44.9 Repeat ;direction and speed the Balls move Ball\xs# = 0 Ball\ys# = 0 Ball\zs# = .011 Until (Ball\zs# > 0.01 Or Ball\zs# < -0.01) End Function