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

S

shrunkenmaster

Guest
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.
 
M

matthulm

Guest
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();
   }
}
 
S

shrunkenmaster

Guest
Thanks for the reply matthulm. Just realised that the player collision was causing another pickup, problem solved.
 
Top