parententity + positionentity O_o

Blitz3D Forums/Blitz3D Beginners Area/parententity + positionentity O_o

I want a group of cubes (parented to another bigger cube) to move first in a way and, when they reach a certain x value, to invert their direction...
and I want the same thing when they reach a -x value...
Well this code makes weird things so... if you can help me...
Graphics3D 800,600,32,2
SetBuffer BackBuffer()

Global cam = CreateCamera()
PositionEntity cam,0,0,0

Global lux = CreateLight()
PositionEntity lux,0,10,0

Global cube = CreateCube()
PositionEntity cube,0,0,10

Type mov
 Field obj
 Field x#
 Field y#
 Field z#
End Type
Global xinc#=-1.3
Global yinc#= 1
Global direction#=.01

For a = 0 To 19
 mov1.mov = New mov
  mov1\obj = CreateCube()
  EntityColor mov1\obj,120,120,120
  ScaleEntity mov1\obj,.1,.1,.1
  If xinc > 2 Then yinc = yinc - 1 : xinc = -1.3
  mov1\y = yinc
  mov1\x = 0.1 + xinc
  xinc = xinc + 1.0
  mov1\z = -3
  EntityParent mov1\obj,cube
  PositionEntity mov1\obj,mov1\x,mov1\y,mov1\z
Next

While Not KeyDown(1)

If KeyDown(203) Then TurnEntity cube,0,-1,0
If KeyDown(205) Then TurnEntity cube,0,1,0
If KeyDown(200) Then MoveEntity cam,0,0,.1
If KeyDown(208) Then MoveEntity cam,0,0,-.1
MoveEntity cam,0,0,0
TurnEntity cube,0,0,0

For mov1.mov = Each mov
 PositionEntity mov1\obj,mov1\x,mov1\y,mov1\z
 If mov1\x > 3.9 Or mov1\x < -3.9 Then direction =  -direction
 mov1\x = mov1\x + direction
Next

RenderWorld()
UpdateWorld()
Flip
Wend
End