• 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!

Moving Platforms Changing Direction

I been trying to code a way on how to change directions of moving platforms, without using some type of block as an barrier.

Here is what i have so far. For some reason, when I insert the code and play the game, i get a compile error saying that i got a malformed "if" statement

Step Event:

Code:
vsp = dir * movespeed;


// Move Directions

if reverse_direction = 1{
    alarm[0] = 40;
    reverse_direction = 0;
}
 
//Vertical Collision

if (place_meeting(x,y+vsp,obj_wall))
{
    while(!place_meeting(x,y+sign(vsp),obj_wall))
    {
    y += sign (vsp);
    }
    vsp = 0;
   
    dir *= -1;

}
y += vsp;

if (instance_exists(obj_Klover))
{
    if round (obj_Klover.y + (obj_Klover.sprite_height/2) > y) || (obj_Klover.key_down) mask_index = -1;
    else
    {
    mask_index = spr_platform;
    if place_meeting(x,y-1,obj_Klover)
    {
        obj_Klover.vsp_carry = vsp;
    }
   
    }  
 }

Alarm Event:

Code:
vspeed = vspeed
reverse_direction = 1
 
Last edited:

Joe Ellis

Member
I'm not sure why it wont work, but
Code:
// Move Directions

if reverse_direction = 1{
    alarm[0] = 40;
    reverse_direction = 0;
}
Code:
vspeed = vspeed
reverse_direction = 1
none of this is doing anything, vspeed=vspeed is like changing 20 into 20 lol

and nothing is happening with the dir when reverse_direction=1

but I dont see why
dir *= -1;
wont work, I might look at it in gm and test it, are you new at gml? you seem experienced in some other language
 
I'm not sure why it wont work, but
Code:
// Move Directions

if reverse_direction = 1{
    alarm[0] = 40;
    reverse_direction = 0;
}
Code:
vspeed = vspeed
reverse_direction = 1
none of this is doing anything, vspeed=vspeed is like changing 20 into 20 lol

and nothing is happening with the dir when reverse_direction=1

but I dont see why
dir *= -1;
wont work, I might look at it in gm and test it, are you new at gml? you seem experienced in some other language
I'm not experience,lol. Its code which i found on a tutorial on youtube about moving platforms. I'm still learning the game maker language and I been trying to learn it for about a month now( or 2).
 

TheouAegis

Member
You should study the manual and the tutorials that are available for direct download in Studio rather than YouTube tutorials which are often buggy or illegible.
 
Top