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

Walk Script

J

Jabes11

Guest
I've seen other posts on this, but this script isn't working. Not sure why. I've got it set to step on the object. Thanks for any help.

Code:
if((keyboard_check(vk_up)))
{

    self.y -= 2;

}else if(keyboard_check(vk_up) && keyboard_check(vk_right))
{

 self.x += 2;
 self.y -=2;

}else if(keyboard_check(vk_right))
{

  self.x += 2;

}else if(keyboard_check(vk_down) && keyboard_check(vk_right))
{

  self.x += 2;
  self.y += 2;

}else if(keyboard_check(vk_down))
{

    self.y += 2;

}else if(keyboard_check(vk_left))
{

    self.x -= 2;

}else if(keyboard_check(vk_left) && keyboard_check(vk_up))
{

    self.x -= 2;
    self.y += 2;

}
 

TheouAegis

Member
You need to check dual-directions first, singular directions last. Your elses are right, though!

Programming is verbal logic. Read your code out loud to yourself and think about what you're actually telling the computer.
 
J

Jabes11

Guest
You need to check dual-directions first, singular directions last. Your elses are right, though!

Programming is verbal logic. Read your code out loud to yourself and think about what you're actually telling the computer.
Not sure I understand the difference of checking ordinal directions first :( Should I be using else if's like this or simply use ifs and check the dual directions first?

Thanks for the reply.
 

TheouAegis

Member
if cardinal
else
if cardinal
else
if cardinal
else
if cardinal
else
if ordinal
else
if ordinal
else
if ordinal
else
if ordinal
 
J

Jabes11

Guest
I gotcha. Got this working, thanks. I'm having an issue with such a simple task. Drag and drop. I've got it set up just like the YouTube video, lol. Square sprite inside a room. Left click event, x=mouse_x, y=mouse_y;

for some reason the object will only drag sketchily southeast, we'll say. Towards lower right corner of the screen.

This is a new project with no other codes attached to anything.

Any idea why my system is working like that? There should be nothing to this according to the YouTube video.

Thanks again.
 
Last edited by a moderator:
M

montiedragon

Guest
I gotcha. Got this working, thanks. I'm having an issue with such a simple task. Drag and drop. I've got it set up just like the YouTube video, lol. Square sprite inside a room. Left click event, x=mouse_x, y=mouse_y;

for some reason the object will only drag sketchily southeast, we'll say. Towards lower right corner of the screen.

This is a new project with no other codes attached to anything.

Any idea why my system is working like that? There should be nothing to this according to the YouTube video.

Thanks again.
It seems that when the sprite is at the mouse position it no longer is being clicked on. Try to change the sprite offset to the center of the image. Though it may be better to do something like this:
Create Event
Code:
drag = false;
Left Pressed Event
Code:
drag = true;
Global Left Release Event
Code:
drag = false;
Step Event
Code:
if (drag){
     x = mouse_x;
     y = mouse_y
     }
 
Top