[Solved] Basic Programming Problema [:D]

E

espiadimonis

Guest
Hello, lovely gamemakers

I wanted to check if the player is falling by creating this varaible: falling = (yprevious < y),

I'm drawing it on the screen to test it and it always returns 0.

I've been messing around with it:
falling = (y + yprevious), returns the expected value, let's say 1235
but,​
falling = (y - yprevious) returns 0
I also created a variable: veamos = (y == yprevious), which returns 1
So y and yprevious have the same value, even though the player is moving up and down the screen :/
 
M

maratae

Guest
Well, assuming y and yprevious do their job, you can achieve what you want with:
Code:
if (y > yprevious)
{
    falling = true;
}
else
{
    falling = false;
}
Or the simplest version, since the (y > yprevious) comparison returns a boolean:
Code:
falling = (y > yprevious);
 
E

espiadimonis

Guest
I'm using GM1.4.1772

I did as you said, and it still returns 0.

Weird. I belive y is being equal to yprevious
 
E

espiadimonis

Guest
Yes. I tried in the Begin Step and in the End Step too, but they still appear to have the same value
 

Paskaler

Member
You could also try checking if the vertical speed is greater 0. I don't know if you're using in-built ones or custom movement variables, but the check remains the same.
 
E

espiadimonis

Guest
I'm working in End Step now. Where y - yprevious is different than 0, but the variable falling still returns false
 
E

espiadimonis

Guest
You could also try checking if the vertical speed is greater 0. I don't know if you're using in-built ones or custom movement variables, but the check remains the same.
Yes, you are right.

What's your vertical movement code?
HA! Solved it! I was checking the variable falling before actually applying the vertical speed to y.

Thank you, you made me think about that

and sorry, that was quite an ignorant move on my behalf
 
Top