Previous frame check?

Blitz3D Forums/Blitz3D Beginners Area/Previous frame check?

chwaga(Posted 2007) [#1]
is there any command to say "if in the previous frame(loop), this=true"? i just need something to check if the character was not on the ground the previous loop, but now is, play this sound (basic hitting-the-ground sound effect without constantly looping it while on the ground).


Buggy(Posted 2007) [#2]
There's no command that does that, per se, but you can easily implement a boolean variable, "isTouched." isTouched is updated every loop, and before it's updated in the current loop, check if isTouched is false and the player's now touching the ground...

...did that make sense?


chwaga(Posted 2007) [#3]
ok, i tried what you said but it isnt playing the sound, here's what i've got:

hitground=LoadSound("land1.wav")
groundhit#=0
;____________________________________________________
While Not KeyDown(1)


If CountCollisions (camera)=True Then cam_hit_ground#=1
If CountCollisions (man)=False Then TranslateEntity man,0,-2.7,0

If KeyDown(203) And CountCollisions (camera)=False Then TurnEntity campiv,0,3,0
If KeyDown(205) And CountCollisions (camera)=False Then TurnEntity campiv,0,-3,0
If KeyDown(208) Then TurnEntity campiv,3,0,0
If KeyDown(200) Then TurnEntity campiv,-3,0,0

If KeyDown(57) Then TranslateEntity man,0,5,0
If KeyDown(17) Then MoveEntity man,0,0,1.5
If KeyDown(30) Then TurnEntity man,0,3,0
If KeyDown(32) Then TurnEntity man,0,-3,0
If KeyDown(31) Then MoveEntity man,0,0,-1


If CountCollisions(doorzone)=True Then doornear#=1
If CountCollisions(doorzone)=False Then doornear#=0
;If CountCollisions(doorzone)=True Then TranslateEntity door,0,2,0
;If CountCollisions(doorzone)=False Then TranslateEntity door,0,-2,0
If doornear#=0 And EntityY(door)>60 Then
TranslateEntity door,0,-2,0
;TranslateEntity doorzone,0,0,-2
EndIf
If doornear#=1 And EntityY(door)<200 Then
TranslateEntity door,0,2,0
;TranslateEntity doorzone,0,2,0
EndIf

If CountCollisions (cantina)=True And groundhit#=0 Then PlaySound hitground
If CountCollisions (cantina)=False Or CountCollisions (plane)=False Then
groundhit#=0
Else
groundhit#=1
EndIf


b32(Posted 2007) [#4]
I think it is best to solve this problem one step at the time:
First, make a variable that is one when cantina collides with the floor, and zero when it doesn't. Make sure it is right by putting Text 0, 0, groundhit before Flip.
After that, use another variable, ie: 'oldgroundhit', to store the previous state of groundhit.
Sort of like this:
oldgroundhit = groundhit
groundhit = countcollision > 0

Then you can use:
If (not oldgroundhit) And (groundhit) Then etc.
When using AND in an If statement, it is best to use brackets. Otherwise the expression could be ambiguous:
If CountCollisions (cantina)=False Or CountCollisions (plane)=False
For instance:
x = False or y = true
could mean
(x=false) or (y=true)
or
x=(false or y = true)
causing inpredicable results.


chwaga(Posted 2007) [#5]
it still isnt working, this is what i've got:

hitground=LoadSound("land1.wav")
oldgroundhit#=groundhit#
groundhit#=False
;oldgroundhit#=groundhit#
;____________________________________________________
While Not KeyDown(1)



If CountCollisions (camera)=True Then cam_hit_ground#=1
If CountCollisions (man)=False Then TranslateEntity man,0,-2.7,0

If KeyDown(203) And CountCollisions (camera)=False Then TurnEntity campiv,0,3,0
If KeyDown(205) And CountCollisions (camera)=False Then TurnEntity campiv,0,-3,0
If KeyDown(208) Then TurnEntity campiv,3,0,0
If KeyDown(200) Then TurnEntity campiv,-3,0,0

If KeyDown(57) Then TranslateEntity man,0,5,0
If KeyDown(17) Then MoveEntity man,0,0,1.5
If KeyDown(30) Then TurnEntity man,0,3,0
If KeyDown(32) Then TurnEntity man,0,-3,0
If KeyDown(31) Then MoveEntity man,0,0,-1


If CountCollisions(doorzone)=True Then doornear#=1
If CountCollisions(doorzone)=False Then doornear#=0
;If CountCollisions(doorzone)=True Then TranslateEntity door,0,2,0
;If CountCollisions(doorzone)=False Then TranslateEntity door,0,-2,0
If doornear#=0 And EntityY(door)>60 Then
TranslateEntity door,0,-2,0
;TranslateEntity doorzone,0,0,-2
EndIf
If doornear#=1 And EntityY(door)<200 Then
TranslateEntity door,0,2,0
;TranslateEntity doorzone,0,2,0
EndIf

;If (CountCollisions (cantina)=True) And (groundhit#=0) Then PlaySound hitground
;If (CountCollisions (cantina)=False) Or (CountCollisions (plane)=False) Then
;groundhit#=0
;Else
;groundhit#=1
;endIf

If (oldgroundhit#=True) And (groundhit#=False) Then PlaySound hitground