fire effect quits working; entity does not exist
Blitz3D Forums/Blitz3D Beginners Area/fire effect quits working; entity does not exist
| ||
Hi, I'm trying the "fire effect" code in the 3d examples. I got it to work on the first level of a 3 level game. My game switches via "goto" statements. When the second level is loading it generates the error "the entity does not exist." It just existed in the first level and I am at a loss to understand why it does not work or how to fix it so it does work. The code I use follows. Anyone have the same experience or recognize how to fix it? The error occurs here, at the> Add_Flame(Entityx... part. It says: Entity does not exist. It worked/existed in the first level but not in the rests of the program. ;Update all fires Function Update_Fires() For a.fire=Each fire Add_Flame(EntityX(a\piv),EntityY(a\piv),EntityZ(a\piv),Rnd(1,4),.04,a\dx,a\dy,a\dz) Next Update_Flames() End Function More complete code below. Global flame01=LoadSprite("gameart\base.bmp") ;Each Flame of the fire Type flame Field ent Field ang# Field size# Field alph# Field dis# Field dx#, dy#, dz# End Type ;The fire itself Type fire Field piv ; Direction Field dx#, dy#, dz# End Type ;Add a flame to the fire Function Add_flame(x#,y#,z#,size#=1,dis#=.016,dx#=0,dy#=0.3,dz#=0) a.flame=New flame a\ent=CopyEntity(flame01) PositionEntity a\ent,x,y,z a\alph=1 a\size=size a\dis=dis a\ang=Rnd(360) ScaleSprite a\ent,a\size,a\size EntityColor a\ent,Rnd(150,255),Rnd(0,100),0 a\dx=dx a\dy=dy a\dz=dz End Function ;Update flames Function Update_flames() For a.flame=Each flame If a\alph>0.01 Then a\alph=a\alph-a\dis EntityAlpha a\ent,a\alph RotateSprite a\ent,a\ang a\ang=a\ang+.2 MoveEntity a\ent,a\dx,a\dy,a\dz Else FreeEntity a\ent Delete a End If Next End Function ;Erase all flames Function Erase_flames() For a.flame=Each flame If a\ent<>0 Then FreeEntity a\ent Next Delete Each flame End Function ;Update all fires Function Update_Fires() For a.fire=Each fire Add_Flame(EntityX(a\piv),EntityY(a\piv),EntityZ(a\piv),Rnd(1,4),.04,a\dx,a\dy,a\dz) Next Update_Flames() End Function ;Add a fire to the scene Function Add_Fire.fire(x#,y#,z#,dx#=0,dy#=.23,dz#=0) a.fire=New fire a\piv=CreatePivot() PositionEntity a\piv,x,y,z a\dx=dx:a\dy=dy:a\dz=dz Return a End Function tfire.fire=Add_Fire(0,0,0) ;in main loop Update_Fires() ;remove after 25 iterations se = se + 1 If se >= 25 Then HideEntity flame01 ;erase_Flames HideEntity Exp1 TranslateEntity tfire\piv,0,5000,0 End If ;locate the fire at target collision PositionEntity tfire\piv,CollisionX#(bullet(q),1),CollisionY#(bullet(q),1),CollisionZ#(bullet(q),1) Thanks Gerald Nelson |
| ||
In Add_Flame piv is the only entity so that is what does not exist. If it used to exist then it got freed somewhere. If this a new fire then perhaps piv never existed. I know that is a little vague but these are just general thoughts about where to look for trouble. |
| ||
hi, I kept trying and now I could get the three subrutines to load and start at least. I changed something and now I can't get the fire to load. It was crashing saying that memory access violation and the debugger pointed at the render world. I am guessing this means I was overloading my cpu and ram. I need to get the erase function correct. I do not know how to read code like flame.piv\fire= a.fire. It is not plain basic. Is it C++ or something? Is it just type code and I don't recognize it? My new subroutine followes. This one loaded all 3 levels but crashed when played, memory access violation: render world. It worked half way through the level. Global flame01=LoadSprite("gameart\base.bmp") .stwof2 flame02=LoadSprite("gameart\base2.bmp"):HideEntity flame02 ;a\piv=CreatePivot() ;Each Flame of the fire Type flame2 Field ent2 Field ang2# Field size2# Field piv2;mine Field alph2# Field dis2# Field dx2#, dy2#, dz2# End Type ;The fire itself Type fire2 Field piv2 ; Direction Field dx2#, dy2#, dz2# End Type ;Add a fire to the scene Function Add_Fire2.fire2(x2#,y2#,z2#,dx2#=0,dy2#=.23,dz2#=0) a2.fire2=New fire2 a2\piv2=CreatePivot() PositionEntity a2\piv2,x2,y2,z2 a2\dx2=dx2:a2\dy2=dy2:a2\dz2=dz2 Return a2 End Function ;Add a flame to the fire Function Add_flame2(x2#,y2#,z2#,size2#=1,dis2#=.016,dx2#=0,dy2#=0.3,dz2#=0) a2.flame2=New flame2 flame02=LoadSprite("gameart\base2.bmp") a2\ent2=CopyEntity(flame02) ;a2\ent2=LoadSprite("gameart\base2.bmp") PositionEntity a2\ent2,x2,y2,z2 a2\alph2=1 a2\size2=size2 a2\dis2=dis2 a2\ang2=Rnd(360) ScaleSprite a2\ent2,a2\size2,a2\size2 EntityColor a2\ent2,Rnd(150,255),Rnd(0,100),0 a2\dx2=dx2 a2\dy2=dy2 a2\dz2=dz2 End Function ;Update flames Function Update_flames2() For a2.flame2=Each flame2 If a2\alph2>0.01 Then a2\alph2=a2\alph2-a2\dis2 EntityAlpha a2\ent2,a2\alph2 RotateSprite a2\ent2,a2\ang2 a2\ang2=a2\ang2+.2 MoveEntity a2\ent2,a2\dx2,a2\dy2,a2\dz2 Else FreeEntity a2\ent2 Delete a2 End If Next End Function ;Erase all flames Function erase_Flames2() For a2.flame2=Each flame2 If a2\ent2<>0 Then FreeEntity a2\ent2 Next Delete Each flame2 End Function ;Update all fires Function Update_Fires2() For a2.fire2=Each fire2 Add_flame2(EntityX(a2\piv2),EntityY(a2\piv2),EntityZ(a2\piv2),Rnd(1,4),.04,a2\dx2,a2\dy2,a2\dz2) ;Add_flame EntityX(x),EntityY(y),EntityZ(z),Rnd(1,4),.04,a\dx,a\dy,a\dz ;Add_flame(x#,y#,z#,size#=1,dis#=.016,dx#=0,dy#=0.3,dz#=0) Next Update_Flames2() End Function ;Erase all fires Function Erase_Fires2() For a2.fire2=Each fire2 If a2\piv2<>0 Then FreeEntity a2\piv2 Next Delete Each fire2 End Function Return .stwof3 flame03=LoadSprite("gameart\base3.bmp"):HideEntity flame03 ;a\piv=CreatePivot() ;Each Flame of the fire Type flame3 Field ent3 Field ang3# Field size3# Field piv3;mine Field alph3# Field dis3# Field dx3#, dy3#, dz3# End Type ;The fire itself Type fire3 Field piv3 ; Direction Field dx3#, dy3#, dz3# End Type ;Add a fire to the scene Function Add_Fire3.fire3(x3#,y3#,z3#,dx3#=0,dy3#=.23,dz3#=0) a3.fire3=New fire3 a3\piv3=CreatePivot() PositionEntity a3\piv3,x3,y3,z3 a3\dx3=dx3:a3\dy3=dy3:a3\dz3=dz3 Return a3 End Function ;Add a flame to the fire Function Add_flame3(x3#,y3#,z3#,size3#=1,dis3#=.016,dx3#=0,dy3#=0.3,dz3#=0) a3.flame3=New flame3 flame03=LoadSprite("gameart\base3.bmp") a3\ent3=CopyEntity(flame03) ;a3\ent3=LoadSprite("gameart\base3.bmp") PositionEntity a3\ent3,x3,y3,z3 a3\alph3=1 a3\size3=size3 a3\dis3=dis3 a3\ang3=Rnd(360) ScaleSprite a3\ent3,a3\size3,a3\size3 EntityColor a3\ent3,Rnd(150,255),Rnd(0,100),0 a3\dx3=dx3 a3\dy3=dy3 a3\dz3=dz3 End Function ;Update flames Function Update_flames3() For a3.flame3=Each flame3 If a3\alph3>0.01 Then a3\alph3=a3\alph3-a3\dis3 EntityAlpha a3\ent3,a3\alph3 RotateSprite a3\ent3,a3\ang3 a3\ang3=a3\ang3+.2 MoveEntity a3\ent3,a3\dx3,a3\dy3,a3\dz3 Else FreeEntity a3\ent3 Delete a3 End If Next End Function ;Erase all flames Function erase_Flames3() For a3.flame3=Each flame3 If a3\ent3<>0 Then FreeEntity a3\ent3 Next Delete Each flame3 End Function ;Update all fires Function Update_Fires3() For a3.fire3=Each fire3 Add_flame3(EntityX(a3\piv3),EntityY(a3\piv3),EntityZ(a3\piv3),Rnd(1,4),.04,a3\dx3,a3\dy3,a3\dz3) ;Add_flame EntityX(x),EntityY(y),EntityZ(z),Rnd(1,4),.04,a\dx,a\dy,a\dz ;Add_flame(x#,y#,z#,size#=1,dis#=.016,dx#=0,dy#=0.3,dz#=0) Next Update_Flames3() End Function ;Erase all fires Function Erase_Fires3() For a3.fire3=Each fire3 If a3\piv3<>0 Then FreeEntity a3\piv3 Next Delete Each fire3 End Function Return .stwof flame04=LoadSprite("gameart\base4.bmp"):HideEntity flame04 ;Each Flame of the fire Type flame Field ent Field ang# Field size# Field alph# Field dis# Field dx#, dy#, dz# End Type ;The fire itself Type fire Field piv ; Direction Field dx#, dy#, dz# End Type ;Add a fire to the scene Function Add_Fire.fire(x#,y#,z#,dx#=0,dy#=.23,dz#=0) a.fire=New fire a\piv=CreatePivot() PositionEntity a\piv,x,y,z a\dx=dx:a\dy=dy:a\dz=dz Return a End Function ;Add a flame to the fire Function Add_flame(x#,y#,z#,size#=1,dis#=.016,dx#=0,dy#=0.3,dz#=0) a.flame=New flame flame04=LoadSprite("gameart\base4.bmp") a\ent=CopyEntity(flame04) ;a\ent=LoadSprite("gameart\base4.bmp") PositionEntity a\ent,x,y,z a\alph=1 a\size=size a\dis=dis a\ang=Rnd(360) ScaleSprite a\ent,a\size,a\size EntityColor a\ent,Rnd(150,255),Rnd(0,100),0 a\dx=dx a\dy=dy a\dz=dz End Function ;Update flames Function Update_flames() For a.flame=Each flame If a\alph>0.01 Then a\alph=a\alph-a\dis EntityAlpha a\ent,a\alph RotateSprite a\ent,a\ang a\ang=a\ang+.2 MoveEntity a\ent,a\dx,a\dy,a\dz Else FreeEntity a\ent Delete a End If Next End Function ;Erase all flames Function erase_Flames() For a.flame=Each flame If a\ent<>0 Then FreeEntity a\ent Next Delete Each flame End Function ;Update all fires Function Update_Fires() For a.fire=Each fire Add_flame(EntityX(a\piv),EntityY(a\piv),EntityZ(a\piv),Rnd(1,4),.04,a\dx,a\dy,a\dz) ;Add_flame EntityX(x),EntityY(y),EntityZ(z),Rnd(1,4),.04,a\dx,a\dy,a\dz ;Add_flame(x#,y#,z#,size#=1,dis#=.016,dx#=0,dy#=0.3,dz#=0) Next Update_Flames() End Function ;Erase all fires Function Erase_Fires() For a.fire=Each fire If a\piv<>0 Then FreeEntity a\piv Next Delete Each fire End Function Return tfire.fire=Add_Fire(0,0,0) ;in main loop Update_Fires() ;remove after 25 iterations se = se + 1 If se >= 25 Then HideEntity flame01 ;erase_Flames HideEntity Exp1 TranslateEntity tfire\piv,0,5000,0 End If ;locate the fire at target collision PositionEntity tfire\piv,CollisionX#(bullet(q),1),CollisionY#(bullet(q),1),CollisionZ#(bullet(q),1) I would appreciate any input. I am about a week into this and it is hard... Trog discover fire, fire bad! Gerald Nelson |