Trying to spawn and object, and then making it move to a certain point, and then move to an object.

B

Bas Franken

Guest
This is the code i've written now.


{
while (obj_LETTERS.x <= 800);
{
move_towards_point(800, obj_LETTERS.y, 5);
}
while (obj_LETTERS.x >=800);
{
move_towards_point(obj_doggo.x, obj_doggo.y, 5);
}
}

where obj_LETTERS is the object that is moving from the left side of the screen, and obj_doggo is the object that obj_LETTERS should move towards.
 

samspade

Member
This is the code i've written now.


{
while (obj_LETTERS.x <= 800);
{
move_towards_point(800, obj_LETTERS.y, 5);
}
while (obj_LETTERS.x >=800);
{
move_towards_point(obj_doggo.x, obj_doggo.y, 5);
}
}

where obj_LETTERS is the object that is moving from the left side of the screen, and obj_doggo is the object that obj_LETTERS should move towards.
There are a couple problems with the code, but the biggest one is that while is a bad choice here. At least it is a bad choice if you don't want it to move all at once. While continues to execute, loop through the code, until it is not true meaning that it will just put the letter over the line instantly.

A few other things that may or may not be problems. Where is this code? If it is in obj_LETTERS (why all caps?) you don't need to say obj_LETTERS.x you can just say x, same for obj_letters.y. If it isn't in obj_letters move_towards point, isn't going to work. Additionally since move towards point sets the x and 800 and the while statement is <= 800 it's possible to hit 800 exactly and never exit the while statement, leading to a game crash.

You probably want something like this:

Code:
///step event of obj_letters
if (x < 800) {
    x += 5;
}

if (x >= 800) {
     move_towards_point(obj_doggo.x, obj_doggo.y, 5);
}
 
Top