move for certain time then move back

Y

Yvalson

Guest
so im currently making a platformer for a school project
and I want to make a horizontally moving platform.
its plain simple I thought
look at the pic too see what I made
inside the create event there is movingright = 1 script
and inside alarm 0 there is a movingright = 0 script
and inside alarm 1 there is a movingright = 1 script

but for some reason my platform just keeps going right how can I fix this?
 

Attachments

JeffJ

Member
If movingright keeps being 1 until the alarm triggers, then your code (which is running in step event) will keep resetting alarm[0], hence never advancing beyond that point.

You could remedy this by adding an additional statement like so:

if movingright==1 AND alarm[0]=-1
{
//do stuff
}

This will ensure that the alarm[0] is only set once even if movingright is true.
 
Y

Yvalson

Guest
If movingright keeps being 1 until the alarm triggers, then your code (which is running in step event) will keep resetting alarm[0], hence never advancing beyond that point.

You could remedy this by adding an additional statement like so:

if movingright==1 AND alarm[0]=-1
{
//do stuff
}

This will ensure that the alarm[0] is only set once even if movingright is true.
Thanks man it worked running like a charm now
 
Top