Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Trouble with lifting code :(  (Read 3038 times)

0 Members and 1 Guest are viewing this topic.
Trouble with lifting code :(
« on: August 03, 2013, 03:30:45 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 448
Hey everyone, having troubles with my lifting code. Im using GM 7 Pro. When the action buttun is pressed, the lift sprite wont animate until the arrow keys are pressed :huh:
Step
Code: [Select]
// LINK MOVEMENT ENGINE by GOODNIGHT
var fholdd, fholdu, fholdl, fholdr, cc;

// Check keys
holdd=keyboard_check(vk_down)
holdu=keyboard_check(vk_up)
holdl=keyboard_check(vk_left)
holdr=keyboard_check(vk_right)
// Cancel opposing keys
if holdu && holdd {
    holdu=0
    holdd=0
}
if holdl && holdr {
    holdl=0
    holdr=0
}


// This is where you may want to add other conditionals which keep you from moving,
// such as if you are using an item, or you are in a menu.
// Just add the conditions to the end of this next "if" line.
// example:
// if (holdd ||holdu || holdl || holdr) && !usingshield {

if holdd ||holdu || holdl || holdr && global.menuon = false{
    // If you are holding any key, start moving.
    // Change Link's direction if you weren't already moving.
    if !moving {
        if holdd { dir="D" }
        else if holdu { dir="U" }
        if holdl { dir="L" }
        else if holdr { dir="R" }
    }
    moving=1
    // Direction correction:
    // Get the correct sprite when you walk diagonally then release one arrow.
    if (holdd && !holdl && !holdr) { dir="D" }
    else if (holdu && !holdl && !holdr) { dir="U" }
    else if (holdl && !holdd && !holdu) { dir="L" }
    else if (holdr && !holdd && !holdu) { dir="R" }
    // Prevent direction glitches caused by inhuman keypress timing.
    if (holdd && holdl && dir!="D" && dir!="L") { dir="L" }
    else if (holdd && holdr && dir!="D" && dir!="R") { dir="R" }
    else if (holdu && holdl && dir!="U" && dir!="L") { dir="L" }
    else if (holdu && holdr && dir!="U" && dir!="R") { dir="R" }
// Stop moving if no key is held.
} else { moving=0 }

// If Link is attempting to move now,
if moving {
    // "charge up" the number of pixels to move during this step,
    movestep+=movespeed
    // prepare movement variables,
    xstep=0
    ystep=0
    // and start doing the movement.

    while movestep>=1 {

        // Corner-cutting loop. This for-loop determines if Link is blocked by a solid,
        // but is close enough to its edge to cut around it.
        // If so, a "fake hold" variable is set, and the engine acts as if that arrow key is held.
        // Feel free to change the initial "cc" variable for corner sensitivity.
        // Between 4 and 8 is recommended - even less if your solids have curved masks. Use 0 for none.

        fholdd=0; fholdu=0; fholdl=0; fholdr=0;
        for (cc=6; cc>0; cc-=1) {
            if holdu {
                // If you're walking upwards and blocked by a solid...
                if !place_free(x,y-1) {
                    // ...but pressing left or right, release the "up" key.
                    if holdl || holdr { holdu=0 }
                    // ...but close to the left edge, and NOT holding left or right, and not fake-holding either, perform a fake left hold.
                    // And if you are only 1 pixel from the edge, also perform a fake up hold, to move diagonally through the corner.
                    else if place_free(x-cc,y-1) && !(fholdl || fholdr) { fholdl=1; fholdu=place_free(x-1,y-1) }
                    // Same as above, for the right edge.
                    else if place_free(x+cc,y-1) && !(fholdl || fholdr) { fholdr=1; fholdu=place_free(x+1,y-1) }
                }
            // Same thing transposed for the other three directions:
            } else if holdd {
                if !place_free(x,y+1) {
                    if holdl || holdr { holdd=0 }
                    else if place_free(x-cc,y+1) && !(fholdl || fholdr) { fholdl=1; fholdd=place_free(x-1,y+1) }
                    else if place_free(x+cc,y+1) && !(fholdl || fholdr) { fholdr=1; fholdd=place_free(x-1,y+1) }
                }
            }
            if holdl {
                if !place_free(x-1,y) {
                    if holdu || holdd { holdl=0 }
                    else if place_free(x-1,y-cc) && !(fholdu || fholdd) { fholdu=1; fholdl=place_free(x-1,y-1) }
                    else if place_free(x-1,y+cc) && !(fholdu || fholdd) { fholdd=1; fholdl=place_free(x-1,y+1) }
                }
            } else if holdr {
                if !place_free(x+1,y) {
                    if holdu || holdd { holdr=0 }
                    else if place_free(x+1,y-cc) && !(fholdu || fholdd) { fholdu=1; fholdr=place_free(x+1,y-1) }
                    else if place_free(x+1,y+cc) && !(fholdu || fholdd) { fholdd=1; fholdr=place_free(x+1,y+1) }
                }
            }
        }
        // End corner-cutting loop.

        // Determine the number of pixels to move horizontally and vertically (-1, 0, or 1).
        xstep=(holdr || fholdr)-(holdl || fholdl)
        ystep=(holdd || fholdd)-(holdu || fholdu)
        // If you can move hor. and vert. at the same time, do so.
        if place_free(x+xstep,y+ystep) {
            x+=xstep
            y+=ystep
        } else {
            // Otherwise, just move in the direction that you can.
            if place_free(x+xstep,y) { x+=xstep }
            else if place_free(x,y+ystep) { y+=ystep }
        }
        // If you only moved up, down, left, or right, take 1 (pixel) off your movement steps.
        // If you moved diagonally, take the square root of 2 (about 1.41) off your movement steps.
        // Allowing less diagonal movements per step gives the proper 'slowdown' effect.
        if ((holdd || holdu) && (holdl || holdr)) || ((fholdd || fholdu) && (fholdl || fholdr)) { movestep-=sqrt(2) }
        else { movestep-=1 }
    }
   
   

    // Set the right sprite when you are moving.
     
     if moving =1 && shield_equip = 0{
       execute_string('sprite_index=sprLinkRun'+dir)
        image_speed=animspeed
    }
    else if moving =1 && shield_equip = 1{
       execute_string('sprite_index=sprLinkRunHS'+dir)
        image_speed=animspeed
    }
// If Link is not moving this step,
} else if moving = 0 && shield_equip = 0{
    // Set the right standing sprite.
       execute_string('sprite_index=sprLinkRun'+dir)
        image_index=0
        movestep=0
    }
else if moving = 0 && shield_equip = 1{
         execute_string('sprite_index=sprLinkRunHS'+dir)
        image_index=0
        movestep=0
    }
else if lifting = 1{
         execute_string('sprite_index=sprLinkLift'+dir)
         image_speed = animspeed
    }
       


//Footstep SFX
if moving =0 then alarm[0]=2

// Almighty depth leverage technique
depth=-y

// end of Link Movement

//knockback code
if kb = true{               //add code for place_free behind link HERE. if kb=true && place_free
x+=lengthdir_x(5,kb_dir)
y+=lengthdir_y(5,kb_dir)
kb=false
}

//lifting


   
       
    if carrying = 1{
    execute_string('sprite_index=sprLinkCarry'+dir)
    }

          //  if toss=1 {
    //    execute_string("sound_play(Strike"+string(floor(random(3)+1))+")")
      //  sound_play(Toss)
//        carrying=0
  //      global.action=""
    //    image_index=1
     //   attacking=1
      //  a=instance_place(x,y,objPickup)
    //    a.lifted=0
    //    a.tossed=1
    //    a.tossdir=dir
   // }

       
Z Press
Code: [Select]
//Lift
 if (dir="D" && place_meeting(x,y+1,objPickup)) or (dir="U" && place_meeting(x,y-1,objPickup)) or (dir="L" && place_meeting(x-1,y,objPickup)) or (dir="R" && place_meeting(x+1,y,objPickup)){
    LC=1
}
else{
    LC= 0
}

        if dir="D" && LC = 1 && carrying = 0 {
        lifting=1
        }

    else if dir="U" && LC = 1 && carrying = 0{
        lifting=1
        p=instance_place(x,y-1,objPickup)
        if instance_exists(p){
            p.solid=0
            p.lifted=1
        }
    }
    else if dir="L" && LC = 1 && carrying = 0{
        lifting=1
        p=instance_place(x-1,y,objPickup)
        if instance_exists(p){
            p.solid=0
            p.lifted=1
        }
    }
    else if dir="R" && LC = 1 && carrying = 0{
        lifting=1
        }

//Toss
    if carrying = 1 {
        toss = 1
        }

Animation End
Code: [Select]
if lifting = 1 {
    p=instance_place(x,y,objPickup)
    sound_play(Grab)
    lifting=0
    carrying=1
        }

    lifting=0
Logged
Re: Trouble with lifting code :(
« Reply #1 on: August 03, 2013, 07:14:44 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 262
Goodnight's movement code isn't that easy to adjust, I have made a slight modification, but to be honest I do not know if it will fix your problem. While I'm also using Goodnight's movement script as a basis for links movement, the lifting function ( and other additional functions used are very different from those in your scripts.

Code: [Select]
// LINK MOVEMENT ENGINE by GOODNIGHT
var fholdd, fholdu, fholdl, fholdr, cc;

// Check keys
holdd=keyboard_check(vk_down)
holdu=keyboard_check(vk_up)
holdl=keyboard_check(vk_left)
holdr=keyboard_check(vk_right)
// Cancel opposing keys
if holdu && holdd {
    holdu=0
    holdd=0
}
if holdl && holdr {
    holdl=0
    holdr=0
}


// This is where you may want to add other conditionals which keep you from moving,
// such as if you are using an item, or you are in a menu.
// Just add the conditions to the end of this next "if" line.
// example:
// if (holdd ||holdu || holdl || holdr) && !usingshield {

if holdd ||holdu || holdl || holdr && !global.menuon {
    // If you are holding any key, start moving.
    // Change Link's direction if you weren't already moving.
    if !moving {
        if holdd { dir="D" }
        else if holdu { dir="U" }
        if holdl { dir="L" }
        else if holdr { dir="R" }
    }
    moving=1
    // Direction correction:
    // Get the correct sprite when you walk diagonally then release one arrow.
    if (holdd && !holdl && !holdr) { dir="D" }
    else if (holdu && !holdl && !holdr) { dir="U" }
    else if (holdl && !holdd && !holdu) { dir="L" }
    else if (holdr && !holdd && !holdu) { dir="R" }
    // Prevent direction glitches caused by inhuman keypress timing.
    if (holdd && holdl && dir!="D" && dir!="L") { dir="L" }
    else if (holdd && holdr && dir!="D" && dir!="R") { dir="R" }
    else if (holdu && holdl && dir!="U" && dir!="L") { dir="L" }
    else if (holdu && holdr && dir!="U" && dir!="R") { dir="R" }
// Stop moving if no key is held.
} else { moving=0 }

// If Link is attempting to move now,
if moving {
    // "charge up" the number of pixels to move during this step,
    movestep+=movespeed
    // prepare movement variables,
    xstep=0
    ystep=0
    // and start doing the movement.

    while movestep>=1 {

        // Corner-cutting loop. This for-loop determines if Link is blocked by a solid,
        // but is close enough to its edge to cut around it.
        // If so, a "fake hold" variable is set, and the engine acts as if that arrow key is held.
        // Feel free to change the initial "cc" variable for corner sensitivity.
        // Between 4 and 8 is recommended - even less if your solids have curved masks. Use 0 for none.

        fholdd=0; fholdu=0; fholdl=0; fholdr=0;
        for (cc=6; cc>0; cc-=1) {
            if holdu {
                // If you're walking upwards and blocked by a solid...
                if !place_free(x,y-1) {
                    // ...but pressing left or right, release the "up" key.
                    if holdl || holdr { holdu=0 }
                    // ...but close to the left edge, and NOT holding left or right, and not fake-holding either, perform a fake left hold.
                    // And if you are only 1 pixel from the edge, also perform a fake up hold, to move diagonally through the corner.
                    else if place_free(x-cc,y-1) && !(fholdl || fholdr) { fholdl=1; fholdu=place_free(x-1,y-1) }
                    // Same as above, for the right edge.
                    else if place_free(x+cc,y-1) && !(fholdl || fholdr) { fholdr=1; fholdu=place_free(x+1,y-1) }
                }
            // Same thing transposed for the other three directions:
            } else if holdd {
                if !place_free(x,y+1) {
                    if holdl || holdr { holdd=0 }
                    else if place_free(x-cc,y+1) && !(fholdl || fholdr) { fholdl=1; fholdd=place_free(x-1,y+1) }
                    else if place_free(x+cc,y+1) && !(fholdl || fholdr) { fholdr=1; fholdd=place_free(x-1,y+1) }
                }
            }
            if holdl {
                if !place_free(x-1,y) {
                    if holdu || holdd { holdl=0 }
                    else if place_free(x-1,y-cc) && !(fholdu || fholdd) { fholdu=1; fholdl=place_free(x-1,y-1) }
                    else if place_free(x-1,y+cc) && !(fholdu || fholdd) { fholdd=1; fholdl=place_free(x-1,y+1) }
                }
            } else if holdr {
                if !place_free(x+1,y) {
                    if holdu || holdd { holdr=0 }
                    else if place_free(x+1,y-cc) && !(fholdu || fholdd) { fholdu=1; fholdr=place_free(x+1,y-1) }
                    else if place_free(x+1,y+cc) && !(fholdu || fholdd) { fholdd=1; fholdr=place_free(x+1,y+1) }
                }
            }
        }
        // End corner-cutting loop.

        // Determine the number of pixels to move horizontally and vertically (-1, 0, or 1).
        xstep=(holdr || fholdr)-(holdl || fholdl)
        ystep=(holdd || fholdd)-(holdu || fholdu)
        // If you can move hor. and vert. at the same time, do so.
        if place_free(x+xstep,y+ystep) {
            x+=xstep
            y+=ystep
        } else {
            // Otherwise, just move in the direction that you can.
            if place_free(x+xstep,y) { x+=xstep }
            else if place_free(x,y+ystep) { y+=ystep }
        }
        // If you only moved up, down, left, or right, take 1 (pixel) off your movement steps.
        // If you moved diagonally, take the square root of 2 (about 1.41) off your movement steps.
        // Allowing less diagonal movements per step gives the proper 'slowdown' effect.
        if ((holdd || holdu) && (holdl || holdr)) || ((fholdd || fholdu) && (fholdl || fholdr)) { movestep-=sqrt(2) }
        else { movestep-=1 }
    }
   
   

    // Set the right sprite when you are moving.

     if moving  && !shield_equip && !lifting    {
       execute_string('sprite_index=sprLinkRun'+dir)
        image_speed=animspeed
    }
    else if moving && shield_equip && !lifting    {
       execute_string('sprite_index=sprLinkRunHS'+dir)
        image_speed=animspeed
    }
// If Link is not moving this step,
} else if !moving  && !shield_equip  && !lifting    {
    // Set the right standing sprite.
       execute_string('sprite_index=sprLinkRun'+dir)
        image_index=0
        movestep=0
    }
else if !moving  && shield_equip && !lifting    {
         execute_string('sprite_index=sprLinkRunHS'+dir)
        image_index=0
        movestep=0
}
else if !moving  && !shield_equip  && lifting
         execute_string('sprite_index=sprLinkLift'+dir)
         image_speed = animspeed
    }
       


//Footstep SFX
if moving =0 then alarm[0]=2

// Almighty depth leverage technique
depth=-y

// end of Link Movement

//knockback code
if kb = true{               //add code for place_free behind link HERE. if kb=true && place_free
x+=lengthdir_x(5,kb_dir)
y+=lengthdir_y(5,kb_dir)
kb=false
}

//lifting


   
       
    if carrying = 1{
    execute_string('sprite_index=sprLinkCarry'+dir)
    }

          //  if toss=1 {
    //    execute_string("sound_play(Strike"+string(floor(random(3)+1))+")")
      //  sound_play(Toss)
//        carrying=0
  //      global.action=""
    //    image_index=1
     //   attacking=1
      //  a=instance_place(x,y,objPickup)
    //    a.lifted=0
    //    a.tossed=1
    //    a.tossdir=dir
   // }

       

where did you define animspeed? I don't see its value in any of these codes.

Code: [Select]
//Footstep SFX
if moving =0 then alarm[0]=2

dont know what this part does, perhaps you need to make this, now it also happens when not moving while lifting
Code: [Select]
if !moving && !lifting { alarm[0]=2 }
Logged
Re: Trouble with lifting code :(
« Reply #2 on: August 03, 2013, 07:22:58 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 448
Atom you're awesome, works perfectly :D Animspeed was declared in the create event, and that other bit of code with the alarm was just playing a sound as Link walks, lol Again, Thank you!
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.224 seconds with 40 queries.