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

Legacy GM Snakes moves right when sending the move left command

H

HypSandar

Guest
I'm working on this practice project via tutorial which was published on Feb 15, 2013
Here's a link to it.

Object Snake
Code:
Information about object: obj_snake

Sprite: spr_snake
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:

No Physics Object
Create Event:

execute code:

//Snake speed, 2 blocks of 32x32 per second.
// 30 ticks is 1 second.
currentID = 0;
alarm[0] = 15;

move_snap(32,32);

Alarm Event for alarm 0:

execute code:

if (currentID == 0) {
//Direction
//0 = right
//1 = left
//2 = up
//3 = down
currentID += 1;
alarm[0] = 15;


switch(global.dir) {

case 0:
instance_create(x + 34, y, obj_snake);
break;
case 1:
instance_create(x + 34, y, obj_snake);
break;
case 2:
instance_create(x, y - 34, obj_snake);
break;
case 3:
instance_create(x, y + 34, obj_snake);
break;
// Cases are equal to = "if(global.dir = 0);"

}
}else if(currentID == (global.length - 1)) {

instance_destroy();

}else{

currentID += 1;
alarm[0] = 15;

}

Object Controller


Code:
Information about object: obj_controller

Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:

No Physics Object
Create Event:

execute code:

//Direction
//0 = right
//1 = left
//2 = up
//3 = down



global.dir = 3;
global.length = 4;

Step Event:

execute code:

//Direction
//0 = right
//1 = left
//2 = up
//3 = down


if(keyboard_check_pressed(vk_right)) global.dir = 0;
if(keyboard_check_pressed(vk_left)) global.dir = 1;
if(keyboard_check_pressed(vk_up)) global.dir = 2;
if(keyboard_check_pressed(vk_down)) global.dir = 3;
Issue

Pressing the left button key sends the snake to the right side of the screen
 
H

HypSandar

Guest


This made me lose control over the snake and it heads to the upper direction.
Ill keep looking, you're saying that the problem is in the Snake Alarm script, right?
Not sure what you meant by Controller Step script though.
 
H

HypSandar

Guest
Got it fixed.
Thanks.
Code:
if (currentID == 0) {
//Direction
//0 = right
//1 = left
//2 = up
//3 = down
currentID += 1;
alarm[0] = 15;


switch(global.dir) {

case 0:
instance_create(x + 34, y, obj_snake);
break;
case 1:
instance_create(x - 34, y, obj_snake);
break;
case 2:
instance_create(x, y - 34, obj_snake);
break;
case 3:
instance_create(x, y + 34, obj_snake);
break;
// Cases are equal to = "if(global.dir = 0);"

}
}else if(currentID == (global.length - 1)) {

instance_destroy();

}else{

currentID += 1;
alarm[0] = 15;

}
 
Top