How do I Pick up ONLY one item

Get help using Construct 2

Post » Sun Jul 20, 2014 4:52 am

G'day Ya'll,
I'm making a side scroller platform game, and my Player has to pick up and move a few items. When his is on contact with the item, and the player presses "Space," He can pick up each item independently, carry it above his head, and drop it where he needs to. The problem is IF there are two items stacked on top of each other already -- say a basket and a log -- The character picks up both at once, and holds both above his head.

I'm trying to get it to choose between them, i dont care which is first. I've got the rough idea of families, but can't execute it properly. I've seen another tutorial and picking nearest using "Touch," but my game isn't a touch game, and i can't seem to wrap my mind around how i would compare those ideas. Any Ideas?
B
3
Posts: 8
Reputation: 191

Post » Sun Jul 20, 2014 4:55 am

In your "Space is pressed" to pick up event add a condition "Family : pick top instance" or "Pick random instance" making sure you are checking if the player is overlapping or near the specific instances.

At worst, post/attach your capx, it will make it easier to help you.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,319
Reputation: 87,487

Post » Sun Jul 20, 2014 5:11 am

Wow... was not expecting a reply so fast. thanks.
I think i've backed myself into a circle and I cant see where I can get out of it. I was trying to do the Pick up objects independently, destroying them and respawning them where I wanted (as a different Tut) had explained.

then just upgraded. and tried to mess with some Instance Variables... but cant quite do it.
I get the feeling i'm going to have to recode the stuff which is fine. any help is good help :)
You do not have the required permissions to view the files attached to this post.
B
3
Posts: 8
Reputation: 191

Post » Sun Jul 20, 2014 5:38 am

See attached capx.
You do not have the required permissions to view the files attached to this post.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,319
Reputation: 87,487

Post » Sun Jul 20, 2014 6:09 am

:) Thank you very much... Legend. I think i would have been going around in circle and never gotten it.
I'm not familiar with function / UID features and will read up on it.

I'm sure you're hugely busy being a champion and all.. but if you have any opportunity to explain anything you did/your thought process/any other tutorials you've done that explain it.
I want to make sure I understand it and not just rely on the generosity of others.
All good if not :)


For anyone else that might have this same issue, right now i'm looking at:
https://www.scirra.com/tutorials/361/un ... moke-trail
https://www.scirra.com/tutorials/556/un ... o-families
B
3
Posts: 8
Reputation: 191

Post » Sun Jul 20, 2014 6:23 am

The idea there was to "refactor" a bit what you did.

What you want is to have a single event that handles the fact that you are picking up an object from the family that contains all the object types.
You then pick only the instance that has the highest priority (the instance variable you used).
This is kind of an "input event". The player presses space, overlaps at least a "carryable" object and is not carrying an object at the time. So the intent is to carry the object.
You send the UID (unique identifier) of the picked instance to the function, and the function deals with destroying/spawning the correct type of object.

To do so, I added another family instance variable "type" that allows you to specify what object type is actually picked/passed to the function through the UID.
Notice also that when you are picking an object, after you set the bear boolean "logcarry" or "basketcarry", you also do set "carry" to true, so that it will render the "input event" false and won't execute it again since the bear is carrying an object.

That's about the "only" modification I made, just cleaning and grouping the events so that it makes hopefully sense.

For UID you can read about it in the manual (search UID keyword) and check out the discussions noted down in the "How do I FAQ" in the section "Picking/selecting instance(s)" section.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,319
Reputation: 87,487

Post » Sun Jul 20, 2014 6:37 am

Sweet! Helps me wrap my mind around it... Thanks again for the help! :D
B
3
Posts: 8
Reputation: 191

Post » Wed Dec 24, 2014 4:42 pm

I have a similar issue. Only the object all share the same Sprite. Would this example work the same or do I need to do something else. What I mean by sharing the same sprite is. Itz the same sprite for all the objects, just a different animation frame. I can try and share the .capx if need be.
B
8
S
1
G
1
Posts: 96
Reputation: 632

Post » Thu Dec 31, 2015 2:37 pm

I would also like to know how to modify the code to work with multiple instances of the same sprite. I want to pick up an item and put it down. Only one item can be carried at once.
B
10
S
2
G
1
Posts: 51
Reputation: 848


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, Ryan Kocourek and 2 guests