Newbie coding question/issue!

B

bl4nk

Guest
I'm having problem with the movement of my char. I made a variable for the speed of my char so i can change the variable for a short period on time, on collision with a item(speed buff). I can't seem to figure out how this works , also did a lot of research cant find anything. Thanks in advance!!

***********player movement code(in step event)***********

// Player movement
playermovespd = 4;
playerxpos = x;
playerypos = y;

//playermovingx = x + playermovespd;

playermoveright = keyboard_check(ord("D"));
playermoveleft = keyboard_check(ord("A"));
playermoveup = keyboard_check(ord("W"));
playermovedown = keyboard_check(ord("S"));

if(playermoveright) x = playerxpos + playermovespd;
if(playermoveleft) x = playerxpos - playermovespd;

if(playermoveup) y = playerypos - playermovespd;
if(playermovedown) y = playerypos + playermovespd;

***********speed buff item code(in collision event)***********

fasleortrue = false;

with (other)
{
fasleortrue = true;
playermovespd = 10;
alarm[0]= 300;
}
fasleortrue = false;

*******************************************************************
 

samspade

Member
Can't say for sure, but it looks like you're setting playermovespd to 4 at the start of the step event. If that's the case, you're overwriting whatever you set the speed to anywhere else. Try not setting the speed there and instead setting speed back to 4 in alarm[0].

Also, there's no reason to have falseortrue = false before the with statement and then false after the with statement. You don't need either of those lines.
 
B

bl4nk

Guest
Can't say for sure, but it looks like you're setting playermovespd to 4 at the start of the step event. If that's the case, you're overwriting whatever you set the speed to anywhere else. Try not setting the speed there and instead setting speed back to 4 in alarm[0].

Also, there's no reason to have falseortrue = false before the with statement and then false after the with statement. You don't need either of those lines.
i managed to fix the issue by putting the playermovespd from the step event(wich happens everyframe) to a create event in wich it ahppens nly once it worked!
 
Top