Hello, in my game i have a pushing/pulling code. and its decently long, so im posting it at the end. i have the code where if there is the block(named Push) in front of you, you are allowed to grab it with Z. now if you are grabbing it, you are assigned a place, if you are grabbing it from the left, global.grableft = true and same for the other directions. if you press right while grabbing it from the left, you go right. and ect. now for pulling if you grab it from the left and press left, you go backwards. thats all my code is. for some reason i cannot get this working fluent. im lost on it, so any pointers would be appreciated. also if there is a way to clean up my code for it to be shorter, please tell me. thanks, so what im looking for is a pulling/pushing script that acts like the MM or OOT pulling(im sure the other 3Ds have the same) but on a LTTP style, since i dont like their way of pushing if you hit a wall. thank you once again
-Whitay.
the script:
///Checking if we should start grabbing
if collision_point(x,y+6,Push,true,false) and keyboard_check_pressed(ord("Z"))
{
global.cangrab = true
}
if collision_point(x-6,y,Push,true,false) and keyboard_check_pressed(ord("Z"))
{
global.cangrab = true
}
if collision_point(x,y+6,Push,true,false) and keyboard_check_pressed(ord("Z"))
{
global.cangrab = true
}
if collision_point(x,y-6,Push,true,false) and keyboard_check_pressed(ord("Z"))
{
global.cangrab = true
}
if collision_point(x,y,Push,true,false) and keyboard_check_pressed(ord("Z"))
{
global.cangrab = true
}
else
{
global.cangrab = false
}
//////////////////GRABBING//////////////////
if global.cangrab = true
{
if (alarm[6] < 0 or alarm[6] = 0) and (sprite_index = spr_left or sprite_index = spr_leftS) and keyboard_check_pressed(ord("Z"))
{
global.grableft = true
sprite_index = spr_PushL
image_speed = 0
}
if (alarm[6] < 0 or alarm[6] = 0) and (sprite_index = spr_right or sprite_index = spr_rightS) and keyboard_check_pressed(ord("Z"))
{
global.grabright = true
sprite_index = spr_PushR
image_speed = 0
}
if (alarm[6] < 0 or alarm[6] = 0) and (sprite_index = spr_up or sprite_index = spr_upS) and keyboard_check_pressed(ord("Z"))
{
global.grabup = true
sprite_index = spr_PushU
image_speed = 0
}
if (alarm[6] < 0 or alarm[6] = 0) and (sprite_index = spr_down or sprite_index = spr_downS) and keyboard_check_pressed(ord("Z"))
{
global.grabdown = true
sprite_index = spr_PushD
image_speed = 0
}
//////////////////////PUSHING
if global.grableft = true and keyboard_check_direct(vk_left) and (alarm[6] < 0 or alarm[6] = 0 or alarm[6] = -1) //and keyboard_check_pressed(ord("Z"))
{
global.pushleft = true
sprite_index = spr_PushL
image_speed = 0.3
alarm[6] = 3
}
if global.grabright = true and keyboard_check_direct(vk_right) and (alarm[6] < 0 or alarm[6] = 0 or alarm[6] = -1) //and keyboard_check_pressed(ord("Z"))
{
global.pushright = true
sprite_index = spr_PushR
image_speed = 0.3
alarm[6] = 3
}
if global.grabup = true and keyboard_check_direct(vk_up) and (alarm[6] < 0 or alarm[6] = 0 or alarm[6] = -1) //and keyboard_check_pressed(ord("Z"))
{
global.pushup = true
sprite_index = spr_PushU
image_speed = 0.3
alarm[6] = 3
}
if global.grabdown = true and keyboard_check_direct(vk_down) and (alarm[6] < 0 or alarm[6] = 0 or alarm[6] = -1) //and keyboard_check_pressed(ord("Z"))
{
global.pushdown = true
sprite_index = spr_PushD
image_speed = 0.3
alarm[6] = 3
}
///////////////////////////////PULLING
if global.grableft = true and keyboard_check_direct(vk_right) and (alarm[6] < 0 or alarm[6] = 0 or alarm[6] = -1) and keyboard_check_pressed(ord("Z"))
{
global.pullleft = true
sprite_index = spr_PullL
image_speed = 0.3
alarm[6] = 3
}
if global.grabright = true and keyboard_check_direct(vk_left) and (alarm[6] < 0 or alarm[6] = 0 or alarm[6] = -1) and keyboard_check_pressed(ord("Z"))
{
global.pullright = true
sprite_index = spr_PullR
image_speed = 0.3
alarm[6] = 3
}
if global.grabup = true and keyboard_check_direct(vk_down) and (alarm[6] < 0 or alarm[6] = 0 or alarm[6] = -1) and keyboard_check_pressed(ord("Z"))
{
global.pullup = true
sprite_index = spr_PullU
image_speed = 0.3
alarm[6] = 3
}
if global.grabdown = true and keyboard_check_direct(vk_up) and (alarm[6] < 0 or alarm[6] = 0 or alarm[6] = -1) and keyboard_check_pressed(ord("Z"))
{
global.pulldown = true
sprite_index = spr_PullD
image_speed = 0.3
alarm[6] = 3
}
}
///////////////////KEY RELEASES
if keyboard_check_released(vk_left) and global.pushleft = true and keyboard_check_pressed(ord("Z"))
{
global.grableft = true
sprite_index = spr_PushL
image_speed = 0
alarm[6] = -1
}
if keyboard_check_released(vk_right) and global.pushright = true and keyboard_check_pressed(ord("Z"))
{
global.grabright = true
sprite_index = spr_PushR
image_speed = 0
alarm[6] = -1
}
if keyboard_check_released(vk_up) and global.pushup = true and keyboard_check_pressed(ord("Z"))
{
global.grabup = true
sprite_index = spr_PushU
image_speed = 0
alarm[6] = -1
}
if keyboard_check_released(vk_down) and global.pushdown = true and keyboard_check_pressed(ord("Z"))
{
global.grabdown = true
sprite_index = spr_PushD
image_speed = 0
alarm[6] = -1
}
///////////////////////////////////////////
if keyboard_check_released(ord("Z")) and sprite_index = spr_PushL
{
sprite_index = spr_leftS
global.canpull = false
global.grableft = false
global.grabright = false
global.grabup = false
global.grabdown = false
global.pushup = false
global.pushright = false
global.pushleft = false
global.pushdown = false
global.pullup = false
global.pullright = false
global.pullleft = false
global.pulldown = false
alarm[6] = -1
}
if keyboard_check_released(ord("Z")) and sprite_index = spr_PushR
{
sprite_index = spr_rightS
global.canpull = false
global.grableft = false
global.grabright = false
global.grabup = false
global.grabdown = false
global.pushup = false
global.pushright = false
global.pushleft = false
global.pushdown = false
global.pullup = false
global.pullright = false
global.pullleft = false
global.pulldown = false
alarm[6] = -1
}
if keyboard_check_released(ord("Z")) and sprite_index = spr_PushU
{
sprite_index = spr_upS
global.canpull = false
global.grableft = false
global.grabright = false
global.grabup = false
global.grabdown = false
global.pushup = false
global.pushright = false
global.pushleft = false
global.pushdown = false
global.pullup = false
global.pullright = false
global.pullleft = false
global.pulldown = false
alarm[6] = -1
}
if keyboard_check_released(ord("Z")) and sprite_index = spr_PushD
{
sprite_index = spr_downS
global.canpull = false
global.grableft = false
global.grabright = false
global.grabup = false
global.grabdown = false
global.pushup = false
global.pushright = false
global.pushleft = false
global.pushdown = false
global.pullup = false
global.pullright = false
global.pullleft = false
global.pulldown = false
alarm[6] = -1
}
Alarm[5]:
////if place is free
if place_free(x+4,y)
{
global.canpull = false
global.cangrab = false
global.canpush = false
}
if place_free(x-4,y)
{
global.canpull = false
global.cangrab = false
global.canpush = false
}
if place_free(x,y+4)
{
global.canpull = false
global.cangrab = false
global.canpush = false
}
if place_free(x,y-4)
{
global.canpull = false
global.cangrab = false
global.canpush = false
}
/////if place isnt free
if !place_free(x+4,y) and sprite_index = spr_right
{
global.canpull = true
global.canpush = true
canroll = false
global.cangrab = true
}
if !place_free(x-4,y) and sprite_index = spr_left
{
global.canpull = true
global.canpush = true
canroll = false
global.cangrab = true
}
if !place_free(x,y+4) and sprite_index = spr_down
{
global.canpull = true
global.canpush = true
canroll = false
global.cangrab = true
}
if !place_free(x,y-4) and sprite_index = spr_up
{
global.canpull = true
canroll = false
global.canpush = true
global.cangrab = true
}
alarm[6]:
if sprite_index = spr_PushL and global.pushleft = true
{
x -= 4
sprite_index = spr_PushL
image_speed = 0.3
alarm[6] = 3
}
if sprite_index = spr_PushR and global.pushright = true
{
x += 4
sprite_index = spr_PushR
image_speed = 0.3
alarm[6] = 3
}
if sprite_index = spr_PushU and global.pushup = true
{
y -= 4
sprite_index = spr_PushU
image_speed = 0.3
alarm[6] = 3
}
if sprite_index = spr_PushD and global.pushdown = true
{
y += 4
sprite_index = spr_PushD
image_speed = 0.3
alarm[6] = 3
}
//////////////////////////////////////////////////////////////////
if sprite_index = spr_PullL and global.pullleft = true
{
x += 4
sprite_index = spr_PullL
image_speed = 0.3
alarm[6] = 3
}
if sprite_index = spr_PullR and global.pullright = true
{
x -= 4
sprite_index = spr_PullR
image_speed = 0.3
alarm[6] = 3
}
if sprite_index = spr_PullU and global.pullup = true
{
y += 4
sprite_index = spr_PullU
image_speed = 0.3
alarm[6] = 3
}
if sprite_index = spr_PullD and global.pulldown = true
{
y -= 4
sprite_index = spr_PullD
image_speed = 0.3
alarm[6] = 3
}
my error is half the time i cant even grab it, unless im walking into it. if im walking it glitches up. the whole code isnt working and i have no idea why.