• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

What is wrong with this code?

V

veko

Guest
I have this simple accelleration code on my obj enemy.
He is suppossed to dash towards player and the slow down.
In my create event it sets 1 to alarm[0] and in alarm[0] it sets direction towards player and speed on 50 and resets it self to 500.
And this is what i have on step event for slowing down:
if speed = 50
{
for (i = 0; i < 20; i += 1)
{
speed -= 2.5;
}
}
It seems that this code is not working since it follows the player on speed 50 forever.
If somebody could help me out that would be great. Thank you!
 
V

veko

Guest
Read your code carefully :) out loud.
You're missing a little something :p
It's really simple!

http://docs.yoyogames.com/source/dadiospice/002_reference/001_gml language overview/401_04_expressions.html
But what?! Im sorry but i actually never had such a simple problem that i couldn't solve! I tried to go through the link you gave me but it seems that everything is in order.
Please help me :(
I tried doing this but it doesn't change anything!
Code:
if speed == 50
{
for (var i = 0; i < 20; i++;)
{
speed -= 2.5;
}
}
 

Sabnock

Member
Also you are using a for to loop in the step so all you would see is the object stop not slow down over time.
 

Joe Ellis

Member
asking if its equal to 50 will only make the below code happen when its exactly 50, which it will only be for 1 frame then gradually reduce, so you need to ask if its more than 0, cus anything above 0 is still moving, also "for" loops are for making things happen more than once per frame, you need the object to only reduce speed once per frame, as you only see 1 frame at a time, so anything that happens in between frames will all join together and be displayed in the next frame
 
S

Salvakiya

Guest
may or may not help... depends on your code... but look up friction in the help docs.

if speed>10{friction =.5}else{friction=.1}
 
Top