GML [SOLVED] How To Carry Item Overhead?

F

FadedSketch

Guest
I'm currently working on a Point & Click adventure type game, and in need of some help. I'm trying to get the player to 'hold' an item overhead, meaning, I need the collided instance of said object to have the same x and y of the player. I hope I'm making sense. :confused: And need any other instances of the same object to NOT follow overhead, but stay in their places.

Here's the object's info:
(btw 'Girl' is the player object, 'Object' is the item I want the player to hold. )
Code:
Information about object: Object
Sprite: spr_Object
Solid: false
Visible: true
Depth: -9
Persistent: false
Parent: 
Children: 
Mask: 
No Physics Object

Step Event:
execute code:

if (place_meeting(x, y, Girl))
{
   if (global.has_item = true)
   {
       x = Girl.x; 
       y = Girl.y - 16;
   }
}

Collision Event with object Girl:
execute code:

//Set Has_Item accordingly.
if (global.has_item = false)
{
   global.has_item = true;
}
I've tried doing it a few other ways, but given the same result. Any advice you guys could give me? :p Any and all is appreciated. If you need more info than I've given, just ask and I'll do my best to give sufficient info! ^^
 
S

SVG

Guest
I've tried doing it a few other ways, but given the same result. Any advice you guys could give me? :p Any and all is appreciated.
Code:
if (place_meeting(x, y, Girl) && !global.has_item)
{
   if (global.has_item = true)
   {
       x = Girl.x;
       y = Girl.y - 16;
   }
}
Maybe just check to see if global.hat_item if false with the if statement like above

Edit: Well maybe not, I don't know if it will continue to be held and move with the character

Edit 2: You could make a variable inside girl object to "carry" the instance id (item), then as the girl moves tell in girl step event to move carried item.x / .y to = her x / y.
After you can just clear the variable when dropped, put it back to = 0 and global.has_item = false;
 
Last edited by a moderator:
S

SVG

Guest
Code:
obj_girl
{
Create Event:
      item_held = 0;
Step Event:
      if instance_exists(item_held) {
            item_held.x = x;
            item_held.y = y - 16;
            global.has_item = true;
      } else {
            item_held = 0;
            global.has_item = false; //if you need this at all
      }
Wherever your drop code goes:
      if "whatever makes girl drop item" {
            girl.item_held = 0;[/INDENT]
      }
}
It might help to tell the girl instance to to move the item x / y with girl's x / y instead of telling the item to move its own x / y with the girl's x / y, even though it would work it doesn't make any logical sense for an non-alive item to move with someone, but for the alive thing (girl) to move the object; that's just my way of thinking maybe :p
 
Last edited by a moderator:
F

FadedSketch

Guest
Code:
if (place_meeting(x, y, Girl) && !global.has_item)
{
   if (global.has_item = true)
   {
       x = Girl.x;
       y = Girl.y - 16;
   }
}
Maybe just check to see if global.hat_item if false with the if statement like above

Edit: Well maybe not, I don't know if it will continue to be held and move with the character

Edit 2: You could make a variable inside girl object to "carry" the instance id (item), then as the girl moves tell in girl step event to move carried item.x / .y to = her x / y.
After you can just clear the variable when dropped, put it back to = 0 and global.has_item = false;
Code:
obj_girl
{
Create Event:
      item_held = 0;
Step Event:
      if instance_exists(item_held) {
            item_held.x = x;
            item_held.y = y - 16;
            global.has_item = true;
      } else {
            item_held = 0;
            global.has_item = false; //if you need this at all
      }
Wherever your drop code goes:
      if "whatever makes girl drop item" {
            girl.item_held = 0;[/INDENT]
      }
}
It might help to tell the girl instance to to move the item x / y with girl's x / y instead of telling the item to move its own x / y with the girl's x / y, even though it would work it doesn't make any logical sense for an non-alive item to move with someone, but for the alive thing (girl) to move the object; that's just my way of thinking maybe :p
First off, thank you for the quick response! ^^ I really appreciate it.

Second, your first post makes my player unable to pick things up, since I set the has_item boolean to TRUE when colliding with Object.

Third, i've tried to update the objects' x/y in the player, (using Object.x/y, I also tried other.x/y) but it lagged behind and stopped following when going downward. Seemed to fix that by updating x/y in the object itself, but still have the issue of blocking another instance of the object from being picked up. :confused: Though your way of thinking does make sense! ;)
 
S

SVG

Guest
Second, your first post makes my player unable to pick things up, since I set the has_item boolean to TRUE when colliding with Object.
I actually predicted this already here and yeah I was right haha:
Edit: Well maybe not, I don't know if it will continue to be held and move with the character
in regards to:
Third, i've tried to update the objects' x/y in the player, (using Object.x/y, I also tried other.x/y) but it lagged behind and stopped following when going downward. Seemed to fix that by updating x/y in the object itself
Yeah whatever works haha! That's the important thing :)

My problem is I don't understand what you mean by:
but still have the issue of blocking another instance of the object from being picked up. :confused: Though your way of thinking does make sense! ;)
Meaning I don't know how you want your game-play to be with items for ex: when you pick up one item you want it to auto drop when you come across another item. So how exactly is your game-play?
 
F

FadedSketch

Guest
Meaning I don't know how you want your game-play to be with items for ex: when you pick up one item you want it to auto drop when you come across another item. So how exactly is your game-play?
Ah, sorry about that! I knew I was forgetting something. :D

The player picks up an item by colliding into it. Now, if player collides into another instance of the same object (or a different pick-up item) AND it is still holding something, the collided item stays put, while the player is carrying the original item. And if the player right-clicks, the held item will drop right where the player is (i.e., stop following the player.) Then the player is free to pick another item up. I hope I'm making sense, I'm not the greatest at explaining things... :p
 
S

SVG

Guest
Okay I understand. Unfortunately there's a bit more bugs I can see happening that will have to be addressed:
1.) right clicking drops an item, player won't be able to pick up that same dropped item until she un-collides with it
2.) what you already said about existing held item not dropping when player comes across another item

1st one will be harder but still possible to do and I would need more time to help with that one, but the 2nd issue would be a simple check in the code you have in place:

if (place_meeting(x, y, Girl)) { if (global.has_item = true) { x = Girl.x; y = Girl.y - 16; } }
I would add a check in the if statement if the girl's item_held is equal to 0

Edit: unless there isn't an issue with that lol
 
F

FadedSketch

Guest
Okay I understand. Unfortunately there's a bit more bugs I can see happening that will have to be addressed:
1.) right clicking drops an item, player won't be able to pick up that same dropped item until she un-collides with it
2.) what you already said about existing held item not dropping when player comes across another item

1st one will be harder but still possible to do and I would need more time to help with that one, but the 2nd issue would be a simple check in the code you have in place:



I would add a check in the if statement if the girl's item_held is equal to 0

Edit: unless there isn't an issue with that lol
Ooooh I see, those things would cause bugs. Maybe the first one could be fixed by the player 'dropping' the item 32 pixels ahead of her? That way it wouldn't be colliding with the player.
aaand I think item_held functions the same as my has_item, just an integer instead of a boolean. ;)

Could you explain this a bit more?

maybe: are you turning item_held back to 0 when right-clicking
I... actually haven't set up dropping the item yet. ^^; I've been Trying to keep other instances from following player if has_item is true before implementing the dropping function.
 
  • Like
Reactions: SVG
S

SVG

Guest
Okay I see :D

Ooooh I see, those things would cause bugs.
I meant if "I" were the one programming that game-play concept about the items that you told me, those would be some things to think about, cause if you didn't think of it now then you definitely would when come time to test the game. Maybe you already got that lol :p

Okay so your has_item is a variable inside the object girl correct? So an item checks for collision and should check if there is an item or has_item in on the girl, are you checking for that?
 
S

SVG

Guest
Okay, finally figured out how to get it on my computer haha, I'll take a look now :)
 
S

SVG

Guest
So there was some problems, the other.x wasn't referring to anything, and when there is nothing other than itself that has been established then it will think you're referring to itself, that's why it flies off the screen, but I got it working
 
S

SVG

Guest
I did very little, you almost had it :D here's what changed:
//Girl's create event:
pickup = 0; instead of false.

//Girl's Step Event
///TESTING
if (pickup > 0) // here I see if pickup has an id, this will have an id from the collision check
{
pickup.x = x; //here I refer to the id that's held in pickup
pickup.y = y - 16;
}
//Nothing else needs to be there, everything from the } else { and after needs to go away

//And Girl's Collision with Obj
if (global.has_item = false)
{
pickup = other.id;
global.has_item = true;
}
 
Last edited by a moderator:
F

FadedSketch

Guest
I did very little, you almost had it :D here's what changed:
//Girl's create event:
pickup = 0; instead of false.

//Girl's Step Event
///TESTING
if (pickup > 0) // here I see if pickup has an id, this will have an id from the collision check
{
pickup.x = x; //here I refer to the id that's held in pickup
pickup.y = y - 16;
}
//Nothing else needs to be there, everything from the } else { and after needs to go away

//And Girl's Collision with Obj
if (global.has_item = false)
{
pickup = other.id;
global.has_item = true;
}
Aha! I see! I thought there was a way to kind of 'section off' an instance like that. :D Works like a charm!
Thank you so much for the help! I really appreciate it! ;)
 
  • Like
Reactions: SVG
S

Silver_Mantis

Guest
Aha! I see! I thought there was a way to kind of 'section off' an instance like that. :D Works like a charm!
Thank you so much for the help! I really appreciate it! ;)
Please add [SOLVED] to your title to help out the community! Thank you FadedSketch :)
 
Top