Help on glitch.

Blitz3D Forums/Blitz3D Beginners Area/Help on glitch.

There a glitch in my game that I can not figure out. There are two cars one is contoled by the host and the other is controled by the guest. I have the cars position being updated eveer 1 secound. When the other computer receives the new enemy postion it places the car where it should be but on the 2nd time the position updated the enemy car is positioned somewhere around 0,1,0
but on the third time the enemy is positioned where it is sopose to be and ect. Here my code can you tell me what I am doing wroung.
Graphics3D 1024,768,32,1
SetBuffer BackBuffer()
Global opb = LoadAnimImage("op.bmp",202,61,0,3)
Global mouseim = LoadImage("m.bmp")
Global antion = False
Global hostorjoin 
Global startgame = 0
Global viewmode = 1
Global nickname$ = "Player" 
Global playerid
Global quit 
Global opm
Global full
Const trailcoll = 3
Dim nicknames$(4)
Dim tpos(4)
menu()
Global time# = MilliSecs()
Global time2# = MilliSecs()
Const carcoll = 1
Const wallcoll = 2
Global coll = 0
Global turn = 0
Global starttrail = 0
Global add = 0
Global hudim = LoadImage("hud.bmp")
Global add_flag = False
Global cam_piv = CreatePivot() ;creates pivot 
SeedRnd MilliSecs()
AntiAlias antion 


Global cam = CreateCamera(cam_piv) ;create camra
	CameraViewport cam,0,0,1024,768 ; creates camera viewing area



AmbientLight 255,255,255 ;sets ambeint light 
plane = CreatePlane() ;create plane
	PositionEntity plane,0,1,0 ; position plane
	gridtex = LoadTexture("grid.bmp") ;loadgrid texture
	EntityTexture plane,gridtex ;set grid texture
wall = LoadMesh("wall.x") ; load wall mesh file
	PositionEntity wall,0,-20,0
	EntityAlpha wall,0.3; makes wall transperant
	EntityType wall,wallcoll ;sets collision type
Global c1
Global c2
If hostorjoin = 2
c1 = LoadMesh("car1\car1.x",cam_piv);loads car1 mesh
	EntityRadius cam_piv,0.5 ;sets raduis for collsions
	EntityType cam_piv,carcoll ;sets collusiontype
	PositionEntity c1,0,1,0
	RotateEntity c1,0,-90,0 
	PositionEntity cam,-0.2,1.8,0
	;;enemy
c2 = LoadMesh("car2\car1.x");loads car1 mesh
	EntityRadius c2,0.5 ;sets raduis for collsions
	EntityType c2,carcoll ;sets collusiontype
	PositionEntity c2,0,1,0
	RotateEntity c2,0,-90,0 

	PositionEntity c2,-2,0,6
EndIf 
If hostorjoin = 1
c1 = LoadMesh("car2\car1.x",cam_piv);loads car1 mesh
	EntityRadius cam_piv,0.5 ;sets raduis for collsions
	EntityType cam_piv,carcoll ;sets collusiontype
	PositionEntity c1,0,1,0
	RotateEntity c1,0,-90,0 
	PositionEntity cam,-0.2,1.8,0
	PositionEntity cam_piv,-2,0,6

	;;enemy
c2 = LoadMesh("car1\car1.x");loads car1 mesh
	EntityRadius c2,0.5 ;sets raduis for collsions
	EntityType c2,carcoll ;sets collusiontype
	PositionEntity c2,0,1,0
	RotateEntity c2,0,-90,0 

EndIf 

;;;;;;;;;;;;;;;;;;;;;;;;;
Global trail_mesh=CreateMesh()
Global trail_brush=CreateBrush()
BrushColor trail_brush,0,0,255
BrushBlend trail_brush,3
BrushFX trail_brush,1
Global trail_surf=CreateSurface( trail_mesh,trail_brush )
AddVertex trail_surf,0,2,0,0,0
AddVertex trail_surf,0,0,0,0,1
AddVertex trail_surf,0,2,0,0,0
AddVertex trail_surf,0,0,0,0,1
AddTriangle trail_surf,0,2,3
AddTriangle trail_surf,0,3,1
AddTriangle trail_surf,0,3,2
AddTriangle trail_surf,0,1,3
Global trail_vert=2
EntityType trail_mesh,trailcoll
;;;;;;;;;;;;;;;;;;;;;;;;;
Global trail_mesh2=CreateMesh()
Global trail_brush2=CreateBrush()
BrushColor trail_brush2,255,0,0
BrushBlend trail_brush2,3
BrushFX trail_brush2,1
Global trail_surf2=CreateSurface( trail_mesh2,trail_brush2 )
AddVertex trail_surf2,0,2,0,0,0
AddVertex trail_surf2,0,0,0,0,1
AddVertex trail_surf2,0,2,0,0,0
AddVertex trail_surf2,0,0,0,0,1
AddTriangle trail_surf2,0,2,3
AddTriangle trail_surf2,0,3,1
AddTriangle trail_surf2,0,3,2
AddTriangle trail_surf2,0,1,3
Global trail_vert2=2
;;;;;;;;;;;;;;;;;;;;;;;;;
Collisions carcoll,wallcoll,2,1
Collisions carcoll,carcoll,1,1
;Collisions carcoll,trailcoll,2,1
FlushKeys()

If hostorjoin = 1
SendNetMsg 10,0,playerid,0
Else
While st = 0
If RecvNetMsg()
	If NetMsgType() = 10
	st = 1
	EndIf
EndIf
Wend  
EndIf 	
	
 
updatepos = MilliSecs()
While Not KeyDown(1) 

trail()
online()
If updatepos + 1000 < MilliSecs()  <<<This is where the new postion is sent out. I also think the problem is here.
SendNetMsg 69,EntityX#(cam_piv),playerid,0
SendNetMsg 70,EntityZ#(cam_piv),playerid,0
updatepos = MilliSecs()

EndIf 


add_flag = False 
turn = 0

If  EntityCollided(cam_piv,wallcoll)

	;coll = 1
	;PositionEntity cam,0,50,0
	;TurnEntity cam,90,0,0 
	;coll = 1
	;SendNetMsg 3,"hi",playerid,0 
	
Else 
	If coll = 0
	pos()

	
	EndIf 
EndIf  



 

	RenderWorld 
	UpdateWorld   



Flip

Wend 
End 
Function pos()

If KeyHit(30)
turn = 90 
					AddVertex trail_surf,EntityX(cam_piv),2,EntityZ(cam_piv),0,0
		AddVertex trail_surf,EntityX(cam_piv),0,EntityZ(cam_piv),0,1
		AddTriangle trail_surf,trail_vert,trail_vert+2,trail_vert+3
		AddTriangle trail_surf,trail_vert,trail_vert+3,trail_vert+1
		AddTriangle trail_surf,trail_vert,trail_vert+3,trail_vert+2
		AddTriangle trail_surf,trail_vert,trail_vert+1,trail_vert+3
		trail_vert=trail_vert+2
		SendNetMsg 2,0,playerid,0
add_flag = True

EndIf  
If KeyHit(32)
turn = -90 
					AddVertex trail_surf,EntityX(cam_piv),2,EntityZ(cam_piv),0,0
		AddVertex trail_surf,EntityX(cam_piv),0,EntityZ(cam_piv),0,1
		AddTriangle trail_surf,trail_vert,trail_vert+2,trail_vert+3
		AddTriangle trail_surf,trail_vert,trail_vert+3,trail_vert+1
		AddTriangle trail_surf,trail_vert,trail_vert+3,trail_vert+2
		AddTriangle trail_surf,trail_vert,trail_vert+1,trail_vert+3
		trail_vert=trail_vert+2
		SendNetMsg 4,0,playerid,0
add_flag = True

EndIf
TurnEntity cam_piv,.0,turn,0





MoveEntity cam_piv,0,0,0.3


End Function 
Function trail()

	If turn = 0

							VertexCoords trail_surf,trail_vert,EntityX(cam_piv),2,EntityZ(cam_piv)
		VertexCoords trail_surf,trail_vert+1,EntityX(cam_piv)-0.1,0,EntityZ(cam_piv)
	


	EndIf
	








End Function 
Function hud()

	DrawImage hudim,0,0

End Function 
Function menu()

menuim = LoadImage("menu.bmp")
mouseim = LoadImage("m.bmp")
opb = LoadAnimImage("op.bmp",202,61,0,3)
opm = LoadImage("opmenu.bmp")

full = LoadAnimImage("fullscreen.bmp",250,50,0,3)
anti = LoadAnimImage("anti.bmp",250,50,0,2)
back = LoadImage("back.bmp")
quit = LoadAnimImage("quit.bmp",202,61,0,3)
playonline = LoadAnimImage("online.bmp",202,61,0,3)

While startgame = 0
Cls 
If menutype = 0 And startgame = 0
	DrawImage menuim,0,0;draw main background image
	DrawImage playonline,400,300,onlineframe ; draws play online button

	DrawImage quit,400,550,quitframe ;draws quit button

	If ImagesOverlap(playonline,400,300,mouseim,MouseX(),MouseY()) And MouseDown(1);determines what frame is onlineframe is.
		startgame = 1
		
		menutype = 1
	Else If ImagesOverlap(playonline,400,300,mouseim,MouseX(),MouseY()) 
		onlineframe = 1
	Else
		onlineframe = 0
	EndIf 
frame = 0
	EndIf
	If ImagesOverlap(quit,400,550,mouseim,MouseX(),MouseY()) And MouseDown(1);determines what frame is quitframe is.
		quitframe = 2
		End 
	Else If ImagesOverlap(quit,400,550,mouseim,MouseX(),MouseY()) 
		quitframe = 1
	Else
		quitframe = 0
	EndIf  


	DrawImage mouseim,MouseX(),MouseY() ; draws mouse corser

	

Flip 

Wend 
intonline()
End Function
;INT ONLINE
Function intonline()
Cls 
Graphics 10,10,32,2 ;set graphics so online thing will show up.
hostorjoin = StartNetGame()
Graphics 1024,768,32,viewmode
If hostorjoin = 0
	Print "Fatal Network Error 001"
	Delay 1000
	SetBuffer BackBuffer()
	menu() 
EndIf 
	playerid = CreateNetPlayer(nickname$) ; createplayerid
	If playerid = 0
	Print "Fatal Network Error 002" 
	Delay 1000
	menu()
	EndIf 
If hostorjoin = 1
 
	wait = MilliSecs()
		While wait + 40000 > MilliSecs() 
			If RecvNetMsg()
				If NetMsgType() = 99
				  lobby()
				EndIf 
				If NetMsgType = 98
					Print "Game is full or has already started"
					Delay 1000
					menu()
				EndIf 
			EndIf 
		Wend 
EndIf 
If hostorjoin = 2
lobby()
EndIf  

	
End Function 
Function lobby()

Graphics3D 1024,768,32,1
mouseim = LoadImage("m.bmp")
lob = LoadImage("lobby.bmp")
back = LoadImage("menu.bmp")
np = 1



While xbc = 0
	Cls 
	DrawImage back,0,0
	DrawImage lob,200,200
	DrawImage mouseim,MouseX(),MouseY()
	If hostorjoin = 2
	Text 0,0,np + "/2"

	If RecvNetMsg() And np <> 2
	If NetMsgType() = 100
	np = 2
	SendNetMsg 99,"go",playerid,0
	EndIf 
	Else 
	SendNetMsg 98,"sorry",playerid,NetMsgFrom()
	EndIf 
	
	If KeyDown(57)
	SendNetMsg 1,"start",playerid,0
		xbc = 1
	EndIf 
	EndIf 
		If hostorjoin = 1
	Text 0,0,"2/2"
	
	If RecvNetMsg()
		If NetMsgType() = 1
			
				xbc = 1
			
		EndIf 
	

	EndIf 
EndIf 
Flip 
	 		

Wend 


End Function 		

Function online()

If RecvNetMsg()
	If NetMsgType() = 2
		TurnEntity c2,0,90,0

	EndIf
	If NetMsgType() = 4
		TurnEntity c2,0,90,0

	EndIf

	If NetMsgType() = 69 
	
		PositionEntity c2,NetMsgData(),1,0 <<<This is were the enemy postion is updated. 

	EndIf
	If NetMsgType() = 70 
		PositionEntity c2,0,1,NetMsgData()
		
	EndIf
EndIf 

End Function


Dumb question - but have you commented out the Millisecs() timer part of you code in the main loop? You said you think the problem is there...first up -does it run okay without it?

..Also - isn't better to updateworld then renderworld? You have it backwards which doesn't make sense to my unedumacted, humble, back-woods, superstitous, canker riddled, peasant-self. Cough..

FYI, try using the forum codes when posting code:What are the forum codes?

I found your problem. You are using POSITIONEntity, not MOVEEntity in your online function. The use of PositionEntity is fine (and desired since you want to correct any error that has occured) but you are using it incorrectly. Take note that when a Net message is sent you set the players position to 0, 1, NetMsgData(). Well, it's no wonder that it's at 0, 1, is it?


I also noticed that you are splitting the players position up into two messages. Bad idea. What if one is lost? Send them both at the same time. You will have to combine the X and Z and then decipher the X and Z to do it though.

So change this:
If updatepos + 1000 < MilliSecs() <<<This is where the new postion is sent out. I also think the problem is here.
SendNetMsg 69,EntityX#(cam_piv),playerid,0
SendNetMsg 70,EntityZ#(cam_piv),playerid,0
updatepos = MilliSecs()

EndIf 
to this;
If updatepos < MilliSecs()
	SendNetMsg 69, PlayerPos$(EntityX#(cam_piv), EntityZ#(cam_piv)), playerid, 0
	updatepos = MilliSecs() + 1000
EndIf 
And add this function to your code:
Function PlayerPos$(x#, z#)
	xpos$ = RSet(Left$(x#, 8), 8)
	zpos$ = RSet(Left$(z#, 8), 8)
	Return xpos$ + zpos$
End Function




And then change this:
If NetMsgType() = 69 

PositionEntity c2,NetMsgData(),1,0 <<<This is were the enemy postion is updated. 

EndIf
If NetMsgType() = 70 
PositionEntity c2,0,1,NetMsgData()

EndIf
to this:
If NetMsgType() = 69
	pos$ = NetMsgData()
	PositionEntity c2, Left$(pos$, 8), 1, Right$(pos$, 8)
EndIf


Thankyou. It works fine now.