1
\$\begingroup\$

I'm making a side-scrolling shooter where I want an object to move from right to left (towards negative X), then, when it's passed out on the left side, jump back to beyond the window width (right side) at a randomly determined Y coordinate (using irandom_range) to loop back into view.

This object is not part of the background as it is meant to obstruct the player's movement (similar to Flappy Bird pipes).

I'm using the Drag'n'Drop interface in Game Maker Studio 2. Currently I have this setup, but the object remains at the right-side window edge, moving randomly up and down each step:

Event components

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Your object is locked on the right side of the game window because the Jump To Point block is actually executed every step. If you notice, there's a red text saying Empty next to the If Variable block:

enter image description here

You didn't give any actions to perform when the condition is met, and the other block is always executed. That's the same as writing this GML code:

if (x <= 0);    // does nothing
x = room_width;
y = irandom_range(-416, -32));

To solve it, drag the Jump To Point block at the right of the If Variable block:

enter image description here

The green wire under the If Variable block means all the following instructions will be executed only when conditions are met. GML equivalent:

if (x <= 0)
{
    // condition applies here
    x = room_width;
    y = irandom_range(-416, -32));
}
// condition does not apply from here on
\$\endgroup\$
2
  • \$\begingroup\$ Ah! I thought it linked to the if-statement via the squarish white line connecting them on the left. Thanks! \$\endgroup\$ Apr 25, 2018 at 16:32
  • \$\begingroup\$ Nope, that white line tells you the order blocks are read by the compiler \$\endgroup\$
    – liggiorgio
    Apr 25, 2018 at 16:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .