0
\$\begingroup\$

GameMaker Studio 2 UI showing "x = x + 4" in the Step event of the objectIn the tutorial it told me to add the sprite to the object and then add an event to the object called Step. I did this and then added the sprite to the room.

The GML code I used in the Step event is x = x + 4; to move to the right but when I run the game it does not move at all.

Why doesn't my sprite move to the right when I have this code in the object's Step event?

\$\endgroup\$
8
  • \$\begingroup\$ Can we see the code please? It will help us figure out what's wrong. \$\endgroup\$ Feb 5 '21 at 19:17
  • 1
    \$\begingroup\$ Have you tried a different tutorial? This sounds like very basic functionality that should be covered in many tutorials, so checking another one can help you spot a step that might not have been explained well in the first one you tried. \$\endgroup\$
    – DMGregory
    Feb 5 '21 at 19:18
  • \$\begingroup\$ noobprogrammer the code is x = x + 4; and DMGregory I'll try another tutorial \$\endgroup\$
    – MM1Content
    Feb 5 '21 at 19:25
  • 1
    \$\begingroup\$ I solved it by adding the object instead of the sprite into the room. Now I just need to figure out how to remove the sprite from the room. \$\endgroup\$
    – MM1Content
    Feb 5 '21 at 21:24
  • 1
    \$\begingroup\$ Hello! Your question has been reopened; if you found the solution (as per one of your previous comments), you should post an answer re-stating this; visitors tend to look at the answer text rather than in the comments for clues on how to solve similar issues they have. \$\endgroup\$
    – Vaillancourt
    Sep 29 '21 at 13:14
1
\$\begingroup\$

As mentioned in the comments, you have placed the sprite in the room instead of the object itself. The object is the one that contains the code and functionality, so replace the sprite with the object and then your function will work.

Keep in mind that sprites and objects are placed on a different layer in a room.
Objects are placed on an 'instances' layer. and standalone sprites are placed on an 'Assets' layer.

\$\endgroup\$
0
\$\begingroup\$

That is not a player moving script, but this is:

if (keyboard_check(vk_left)) x = x - 3;
if (keyboard_check(vk_right)) x = x + 3;
if (keyboard_check(vk_up)) y = y - 3;
if (keyboard_check(vk_down)) y = y + 3;

This snippet works for top-down movement. In the first line of code, it basically says 'if you press the left arrow button key on your keyboard, you will move left'.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Although your answer may be useful to some, it doesn't address the main point of the question. \$\endgroup\$
    – liggiorgio
    Aug 28 '21 at 10:31

You must log in to answer this question.

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