1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

[SOLVED] Pick up & drop item issue, some guidance please

Discussion in 'Programming' started by shrunkenmaster, Dec 4, 2019.

  1. shrunkenmaster

    shrunkenmaster Member

    Joined:
    Nov 11, 2019
    Posts:
    16
    I have a pickup/drop object issue that I need some help with.

    The player must pick up an object (oCapPickup) from the central 'bin' and drop it on one of the multiple random places, designated by the oCapGhost objects. Then the player needs to pick up another from the bin, and so on.

    This all works ok with one Ghost object, but not if I increase the amount (variable pn) to 2 or more. I've played around with a few things but I think I'm missing something.

    oInitCapacitor (create)
    Code:
    //draw ghost caps
    pn = path_get_number(cap_path); //get number of points on the path
    pn = 2; //TEST NUMBER
    capsleft = pn;
    
    for (var n = 0; n <pn; n++)
       {
        pp = irandom_range (1, pn); //choose random point
       px = path_get_point_x(cap_path, pp); //set x
       py = path_get_point_y(cap_path, pp); //set y
       
       if (!place_meeting(px,py,oCapGhost)) // check position free and create ghost
           {
               with instance_create_layer(px, py, "Pickup", oCapGhost)
               {
               image_index = 3;
               image_speed = 0;
               }
           }
       }
    
    // draw cap in bin (this one doesn't get picked up)
    global.cap_col = irandom (2);
    with instance_create_layer(248, 350, "Pickup", oCapBin)
       {
       image_index = global.cap_col;
       image_speed = 0;
       }
    
    // draw cap to pick up
    with instance_create_layer(248, 350, "Pickup", oCapPickup)
       {
       image_index = oCapBin.image_index
       image_speed = 0;
       }
    
    oCapPickup ( collision with oCapGhost)
    Code:
    if ((global.carrying = true) && (other.image_index =3) && (oInitCapacitor.capsleft >0))
       
       {oInitCapacitor.capsleft -=1;
               other.image_index = global.cap_col;
               global.carrying = false;
               
               if(oInitCapacitor.capsleft >0)
                   {
                   oCapPickup.x = 248;
                   oCapPickup.y = 250;
                   }
                   
               else instance_destroy();
       }
    
    Hope my desciption makes sense - any help would be great.
     
  2. matthulm

    matthulm Member

    Joined:
    Dec 3, 2019
    Posts:
    7
    What result does this code produce? Are all the objects on screen move to the player? Or does the code not work at all when there is more than one of the object?

    From what I can see, it may be an issue with how the collision code chooses which instance to pick up. Your code looks fine however you're basically telling the game to pick up every instance of oCapPickup

    Try playing around with the 'self' and 'other' statements

    Try wrapping a with(other) { } statement around the code, this basically runs the code with the specific instance of oCapPickup as opposed to all of them in the room

    It should look like this
    Code:
    with(other)
    {
    if ((global.carrying = true) && (other.image_index =3) && (oInitCapacitor.capsleft >0))
      
       {oInitCapacitor.capsleft -=1;
               other.image_index = global.cap_col;
               global.carrying = false;
              
               if(oInitCapacitor.capsleft >0)
                   {
                   oCapPickup.x = 248;
                   oCapPickup.y = 250;
                   }
                  
               else instance_destroy();
       }
    }
     
  3. shrunkenmaster

    shrunkenmaster Member

    Joined:
    Nov 11, 2019
    Posts:
    16
    Thanks for the reply matthulm. Just realised that the player collision was causing another pickup, problem solved.
     
    matthulm likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice