need help "object dose not exist"

Blitz3D Forums/Blitz3D Beginners Area/need help "object dose not exist"

Aussie(Posted 2009) [#1]
Gday all.
I am making a very simple game where targets are launched into the air & you have to shoot them. I have made the targets pickable & set collisions on them. Here is the function i am useing.

Function update_target()
	
	For t.target = Each target
	
	t\targetv#=t\targetv#-.0025
	
	MoveEntity t\piv,t\xv#,t\targetv#,0
	TurnEntity t\mesh,0,t\rot#,0
	
	EntityPickMode t\mesh,2
	
	
	If picked=t\mesh
		score=score+10
		create_puff() 
		FreeEntity picked
		Delete t.target
		picked=CameraPick(camera,1024/2,768/2)
		EndIf
		
	If	EntityCollided (t\piv,plane_col)
		miss=miss+1
		FreeEntity t\piv
		Delete t.target
		EndIf
		
 
	
	Next 
	
End Function


When i added in the "entity collided" section to the function, the game ends when i pick the target & i keep geting "Object dose not exist" I get the same thing if i put the "entity collided" before the "picked" code, except i get the error when the target collides with the plane. I know the reason why it is doing this. I was hopeing someone could help me out with a way around it.
Thanks


Stevie G(Posted 2009) [#2]
Are "picked" and "miss" globally defined?

The code you've posted is not helpful!


Aussie(Posted 2009) [#3]
yep Picked & miss are both global.

Here is the whole Code.

Main Loop
Graphics3D 1024,768,0,1

SetBuffer BackBuffer()


Global camera
Global cam_x#,cam_z#,cam_pitch#,cam_yaw#
Global targetpiv,launcher,target1
Global picked
Global targettimer=MilliSecs()
Global time=3000
Global puff,tgthit
Global my_font = jf_load_font("Fonts\myfont.png")
Global my_fontr = jf_load_font("fonts\myfontred.png")
Global Score=0
Global Miss=0
Global plane_col=1
Global target_col=2

Type target
Field targetv#,mesh,rot#,piv,xv#
End Type

Type targetpuff
Field alpha#,puffsprite
End Type

light=CreateLight()
RotateEntity light,45,0,0

camera=CreateCamera()
	PositionEntity camera,0,5,-5
	CameraClsColor camera,0,200,255
	CameraFogMode camera,1
	CameraFogColor camera,0,200,255
	CameraFogRange camera,100,500

plane=CreatePlane()
	PositionEntity plane,0,-.1,0
	EntityColor plane,0,0,0
	EntityType plane,plane_col
	
terrain=LoadAnimMesh("terrain/myterrain2.x")
PositionEntity terrain,-250,0,-100


loadmeshes()
loadsprites()

Collisions target_col,plane_col,2,1
	
sight=LoadSprite("sprites/sight.tga",2,camera)
	PositionEntity sight,0,0,1.5
	ScaleSprite sight,.05,.05
	
	
SeedRnd MilliSecs()



While Not KeyDown (1)


	If MilliSecs() > targettimer+time Then 
		create_target()
		targettimer=MilliSecs()
	EndIf



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	mxspd#=MouseXSpeed()*.2
	myspd#=MouseYSpeed()*.2
		
	MoveMouse 1024/2, 768/2
	campitch=campitch+myspd
	If campitch<-85 Then campitch=-85
	If campitch>85 Then campitch=85
	camyaw=camyaw-mxspd
	If camyaw<-70 Then camyaw=-70
	If camyaw>70 Then camyaw=70
	RotateEntity camera,campitch,camyaw,0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	If MouseHit(1)
		picked=CameraPick(camera,1024/2,768/2)
	End If 
		
	
update_target()
update_puff()

	
	UpdateWorld
	RenderWorld
jf_text(my_font,10,0,"Score: "+ Score)
jf_text(my_fontr,10,100,"Miss: "+miss)


Flip

Wend

Include "shootnrangefunctions.bb"
Include "Fonts\LIB_juicy_fonts.bb"
End


Functions
Function loadmeshes()
	launcher=LoadMesh("models\launcher1.x")
	PositionEntity launcher,0,1.5,20
	targetpiv=CreatePivot()
	HideEntity targetpiv
	EntityType targetpiv,target_col
	target1=LoadMesh("models\target1.x")
	HideEntity target1
	ScaleEntity target1,1,1,.5
	launcher=LoadMesh("models\launcher1.x")
	PositionEntity launcher,0,1.5,20
End Function

Function loadsprites()
	puff=LoadSprite("sprites/puff.tga",2)
	ScaleSprite puff,2,2
	HideEntity puff
	tgthit=LoadSprite("sprites/tgthit.tga",2)
	ScaleSprite tgthit,2,2
	HideEntity tgthit
End Function

Function create_puff()

	a.targetpuff=New targetpuff
	
	a\puffsprite= CopyEntity (puff)
	
	a\alpha#=1
End Function

Function update_puff()

	For a.targetpuff = Each targetpuff
	PositionEntity a\puffsprite,PickedX(),PickedY(),PickedZ()
	a\alpha#=a\alpha#-.05
	EntityAlpha a\puffsprite,a\alpha#
	If a\alpha=<0 Then 
		FreeEntity a\puffsprite
		Delete a.targetpuff
		EndIf
	Next
	
End Function

Function create_target()
	
	t.target=New target
	
	t\piv=CopyEntity (targetpiv)
	PositionEntity t\piv,EntityX(launcher),EntityY(launcher),EntityZ(launcher)
	
	t\mesh=CopyEntity (target1,t\piv)
		
	t\targetv#=Rnd(.25,.35)
	
	t\rot#=Rnd(1.5,2)
	
	t\xv#=Rnd(-.2,.2)
	
End Function

Function update_target()
	
	For t.target = Each target
	
	t\targetv#=t\targetv#-.0025
	
	MoveEntity t\piv,t\xv#,t\targetv#,0
	TurnEntity t\mesh,0,t\rot#,0
	
	EntityPickMode t\mesh,2
	
	
	If picked=t\mesh
		score=score+10
		create_puff() 
		FreeEntity picked
		Delete t.target
		picked=CameraPick(camera,1024/2,768/2)
		EndIf
		
	If	EntityCollided (t\piv,plane_col)
		miss=miss+1
		FreeEntity t\piv
		Delete t.target
		EndIf
 
	
	Next 
	
End Function

Cheers


Floyd(Posted 2009) [#4]
	If picked=t\mesh
		score=score+10
		create_puff() 
		FreeEntity picked
		Delete t.target
		picked=CameraPick(camera,1024/2,768/2)
		EndIf
		
	If	EntityCollided (t\piv,plane_col)
		miss=miss+1
		FreeEntity t\piv
		Delete t.target
		EndIf

If both If blocks get executed then you are attempting to use a t.target which has just been deleted.
This seems to be the most likely culprit.


Matty(Posted 2009) [#5]
I would agree with Floyd, and go further and say that is definitely the culprit.

You either need to restructure your logic a bit better in that section, or check if t.target is null before entering the second if statement.


GfK(Posted 2009) [#6]
Replacing the EndIf/If with an ElseIf, might also do the job?


GIB3D(Posted 2009) [#7]
or use
If handle(t) <> 0
;Do stuff here
EndIf


That checks to see if your type object thing still exists. So if you delete "t" you can use that to check :)


Aussie(Posted 2009) [#8]
HA HA.... SUCCESS!!!!! Thanks heaps everyone. :)


Aussie(Posted 2009) [#9]
Gday all. Am SOOOO close to finishing my first game but need help with a pause function.
I am able to pause the game & show the pause screen successfully. The only problem i now have is that the targets are launched with the millisecs() & when the game is paused it appears the millisecs() keep going & when i return back to the main game a target is launched straight away. Any sugestions on how to prevent this would be greatly appreciated.

here is the pause code & function.

If KeyHit(25) Then paused=True 
	If paused = True Then game_paused()


Function game_paused()
	FlushKeys
	black =LoadImage("screens/fade.jpg")
	paused = False
While Not KeyDown(0)
	DrawBlock black,0,0
	jf_Text(my_fontyr,200,300,"Game Paused.")
	jf_Text(my_fontyrsml,50,400,"Press P to continue or Q to quit.")
	If KeyHit(25) Cls :FreeImage black :FlushKeys :Return
	If KeyHit(16) End
	Flip
Wend
End Function


the code at the top of the post is still the main framework i am working around so refer to that if needed. Thanks :)


Aussie(Posted 2009) [#10]
Can anyone please help. This is the only thing left to do to finish my game.


PowerPC603(Posted 2009) [#11]
When unpausing, set "targettimer" to MilliSecs() in your game_paused function:
If KeyHit(25) Cls :FreeImage black :FlushKeys :targettimer = MilliSecs() :Return



Matty(Posted 2009) [#12]
I am guessing you have something like this:

if millisecs() > timetolaunchtarget then 
.... and other stuff goes in here

endif 



All you need to do is store the value of millisecs() when the pause is issued, and then when the pause is over add the difference between "pausedattime" and millisecs() to "timetolaunchtarget"


Floyd(Posted 2009) [#13]
You have a variable called targettime which I assume is used for launch decisions.

When you are about to pause the game check the current time and compute

elapsedtime = Millisecs() - tartgettime.

This will be a very small number, for example 5 would mean 5 milliseconds have elapsed since tartgettime was set. This is the situation you want to restore when play resumes.

So when the game resumes you set

targettime = Millisecs() - elapsedtime

and continue as if the pause never happened.


PowerPC603(Posted 2009) [#14]
You could do it this way too, but if the elapsed time was 2990ms before you paused, then the next target will be launched 10ms after unpausing the game, which is not what you want.

I would just reset the timer (targettimer = MilliSecs()), so you have the full 3 seconds after unpausing before the next target gets launched.


Aussie(Posted 2009) [#15]
Thanks heaps everyone. I have now completed my first game in B3d. Now to start geting bigger & better.
:)