object does not exist error
Blitz3D Forums/Blitz3D Beginners Area/object does not exist error
| ||
What does the "object does not exist" error mean when called on "RectsOverlap"? This error is only appearing when the function returns "True". |
| ||
Unless you've made some reference to an image or something by it's handle in the RectsOverlap line, (i.e. RectsOverlap x,y,ImageWidth(Image)... etc.) Then I am unsure of why such an error would occur there. Any chance you could post a relevant section ofyour code that might give a clue? |
| ||
"Object does not exist" normally means you're trying to do something with a custom type variable that's currently Null. Using one? |
| ||
I'm fairly new to blitz so this code may not be very efficient. It is also not complete. Graphics 600,600,8,2 SeedRnd MilliSecs() Global scrx = GraphicsWidth() Global scry = GraphicsHeight() SetBuffer FrontBuffer() Type ent Field xv#,yv# Field x#,y# Field typ$,colr,colg,colb,dia# End Type For n = 1 To 15 CreateRS(Rnd(scrx),Rnd(scry),Rnd(-.5,.5),Rnd(-.5,.5)) Next While Not KeyHit(1) Cls UpdateEnts DrawBord Flip Wend End ;Functions----------------------------------------------- Function DrawBord() For e.ent = Each ent Color e\colr,e\colg,e\colb Oval e\x#-(e\dia#/2),e\y#-(e\dia#/2),e\dia#,e\dia#,True Color 255,255,255 Next End Function Function UpdateEnts() For e.ent = Each ent e\x# = e\x# + e\xv# e\y# = e\y# + e\yv# If e\x# <= 0 Or e\x# >= scrx Then e\xv# = -e\xv# If e\y# <= 0 Or e\y# >= scry Then e\yv# = -e\yv# Next For e.ent = Each ent For c.ent = Each ent If e = c Then Goto Skip If RectsOverlap(e\x#,e\y#,e\dia#,e\dia#,c\x#,c\y#,c\dia#,c\dia#) If e\typ$ = "rs" And c\typ$ = "rs" Or c\typ$ = "rs" And e\typ$ = "rs" CreateRB(e\x#,e\y#) Delete e Delete c End If End If .Skip Next Next End Function ;Create Functions------------------------------------ Function CreateRS(x#,y#,xv#,yv#) e.ent = New ent e\x# = x# e\y# = y# e\xv# = xv# e\yv# = yv# e\colr = 255 e\colg = 0 e\colb = 0 e\dia# = 5 e\typ$ = "rs" End Function Function CreateBS(x#,y#,xv#,yv#) e.ent = New ent e\x# = x# e\y# = y# e\xv# = xv# e\yv# = yv# e\colr = 0 e\colg = 0 e\colb = 255 e\dia# = 5 e\typ$ = "bs" End Function Function CreateRB(x#,y#) e.ent = New ent e\x# = x# e\y# = y# e\colr = 255 e\colg = 0 e\colb = 0 e\dia# = 10 e\typ$ = "rb" End Function Function CreateBB(x#,y#) e.ent = New ent e\x# = x# e\y# = y# e\colr = 0 e\colg = 0 e\colb = 255 e\dia# = 10 e\typ$ = "bb" End Function |
| ||
I haven't gone over all of your code, so there may be more things to improve, but I've fixed the bug and tidied the surrounding code.Graphics 600,600,8,2 SeedRnd MilliSecs() Global scrx = GraphicsWidth() Global scry = GraphicsHeight() SetBuffer FrontBuffer() Type ent Field xv#,yv# Field x#,y# Field typ$,colr,colg,colb,dia# End Type For n = 1 To 15 CreateRS(Rnd(scrx),Rnd(scry),Rnd(-.5,.5),Rnd(-.5,.5)) Next While Not KeyHit(1) Cls UpdateEnts DrawBord Flip Wend End ;Functions----------------------------------------------- Function DrawBord() For e.ent = Each ent Color e\colr,e\colg,e\colb Oval e\x#-(e\dia#/2),e\y#-(e\dia#/2),e\dia#,e\dia#,True Color 255,255,255 Next End Function Function UpdateEnts() For e.ent = Each ent e\x# = e\x# + e\xv# e\y# = e\y# + e\yv# If e\x# <= 0 Or e\x# >= scrx Then e\xv# = -e\xv# If e\y# <= 0 Or e\y# >= scry Then e\yv# = -e\yv# Next For e.ent = Each ent For c.ent = Each ent If e <> c If e<>Null If RectsOverlap(e\x#,e\y#,e\dia#,e\dia#,c\x#,c\y#,c\dia#,c\dia#) If e\typ$ = "rs" And c\typ$ = "rs" Or c\typ$ = "rs" And e\typ$ = "rs" CreateRB(e\x#,e\y#) Delete e Delete c End If End If End If End If Next Next End Function ;Create Functions------------------------------------ Function CreateRS(x#,y#,xv#,yv#) e.ent = New ent e\x# = x# e\y# = y# e\xv# = xv# e\yv# = yv# e\colr = 255 e\colg = 0 e\colb = 0 e\dia# = 5 e\typ$ = "rs" End Function Function CreateBS(x#,y#,xv#,yv#) e.ent = New ent e\x# = x# e\y# = y# e\xv# = xv# e\yv# = yv# e\colr = 0 e\colg = 0 e\colb = 255 e\dia# = 5 e\typ$ = "bs" End Function Quick explanation of what was wrong. You have nested loops going through the same list. For e= and For c= through the same list of objects, ok? So each loop deals with the object, but you may already have deleted it, in which case it won't be valid any more. SO I check that e is not equal to null. I don't think you need to check c, but I only looked quickly. If you get a similar error with c, you may need to check that is <> null before you attempt to use it. It's always a good practice really. I changed your if e=c goto skip because it's harder to read. I've reversed it and said if e <> c then execute the block of code. I also indented a couple for..next loops, again to make things more readable. |
| ||
Thank you very much. |