Got fire to run but won't reload level, problems.

Blitz3D Forums/Blitz3D Beginners Area/Got fire to run but won't reload level, problems.

gerald(Posted 2015) [#1]
Hi,

I'm still trying fire. I finally got the basic effect to load and run but now it won't allow reloading a level. I use f1-3 to start sections of a game. The code won't allow restarting a level, after character dies, or returning to a previous section. In section 1 you can still go to section 2 or 3 but not back to 1.

The update_fires was causing the first problem with memory access violation. I put it in a loop that only calls it when fire is showing. It now finishes the level. I guess you can't update something that isn't there.

I lose so much control with the effect I would like to improve on it.

Any help available?

Gerald












code follows



.game1



Graphics3D 1024,768
SetBuffer BackBuffer()


Global tfire2.fire2=Add_Fire2(0,-25,0)
Global tfire.fire=Add_Fire(0,-25,0)
Global tfire3.fire3=Add_Fire3(0,-25,0)



Global flame04=LoadSprite("gameart\base4.bmp"):HideEntity flame04
Global flame02=LoadSprite("gameart\base2.bmp"):HideEntity flame02
Global flame03=LoadSprite("gameart\base3.bmp"):HideEntity flame03

Global piv=CreatePivot()
Global piv2=CreatePivot()
Global piv3=CreatePivot()




;.game1

Gosub stwof2-
-
-
-
tfire2.fire2=Add_Fire2(0,-23,50)

se = 10
fe = 10

fire = False
main loop

-
-
-
tfire2.fire2=Add_Fire2(0,-23,300)

-
-
se = se + 1

If se > 10 Then
HideEntity exp1
End If


fe = fe + 1
If fe >= 10 And fire = True Then
erase_Flames2
HideEntity Exp1
TranslateEntity tfire2\piv2,0,500,0
fire = False
End If

If fe <= 10 Then
Update_Fires2()
End If
-
-
-
-

;in collision loop
-
-

PositionEntity tfire2\piv2,CollisionX#(bullet(q),1),CollisionY#(bullet(q),1),CollisionZ#(bullet(q),1)
;PositionEntity Exp1,CollisionX#(bullet(q),1),CollisionY#(bullet(q),1),CollisionZ#(bullet(q),1)
;ShowEntity Exp1
ShowEntity tfire2\piv2



fe = 0


-
-

-
;subroutines near end of code file
-


.



.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.fire2=New fire2

;L.fire2=First fire2
;L2.fire2=After L.fire2
;L3.fire2=Last L.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")
;a\ent=CopyEntity(flame02)

a2\ent2=LoadSprite("gameart\base2.bmp")
;a\piv=CreatePivot()

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
;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_flame2(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
;If a2\piv2 = 0 Then FreeEntity a2\piv2

;Next
;Delete Each fire2
;End Function


Return









When the program runs, it has basic function. The level select switches f1-f3, o restart level work but the memory access violation message comes up if you try to play the level. This is only on going back to a level previously accesed. In level 1 you can select level 2 or 3 but you cannot go back to level 1.

This means you cannot restart the level if your character dies. The game must be restarted completely.

Why can’t the levels be restarted? (Or go back to a level?)


gerald(Posted 2015) [#2]
Hi,

Because the tfield costs so much function (reloads, restarts) and I cannot do it well I'm using a wings 3d snow entity and pivoting it at the camera.

createpivot piv(camera)
snow position camera
rotate camera pitchyawroll
trunentity piv,.3,0,0

Let me know if you can figure out my mistakes and correct them or advise me on tfields.

Gerald


RGR(Posted 2015) [#3]
You have 112 forum posts - but still have not had the time to take a look into the forum codes?
Why don't you put your code into code or codebox? This way tabs are kept - code is blitzcode and not changed into html, aso aso aso ...


Irvau(Posted 2015) [#4]
Hmmm....
Lemme try and help out. I'm having a hard time following the flow of this program - I suck at reading code that I didn't spit out.
Ah, well. :P

Anyways, from what I can tell, you have a system that flows using labels.
That's your first error. Well, it's not really an error, but it still makes debugging and running your code a lot more painful than it needs to be. Instead, try using a main loop that initiates after the buffer is set. Have a global keep track of your game state. Select the global in the main loop, and do stuff depending on the state. At the end of the loop, you can update the game state, so that it responds to keys 1-3 being pressed.

Oh, and, yeah, following RGR's tip helps A LOT. Tabs really do help with readability...