How do I pick up only one item at once?

Get help using Construct 2

Post » Sat Jan 02, 2016 9:19 pm

So yeah I want to be able to only carry one item at once.
I want it that when I press z it will drop an item if its carrying something. Only after that if I press Z it will pick up an item.
Also I want to be be able to have a different set of animation when carrying the item. And less jump power.
Code: Select all
https://drive.google.com/file/d/0B6czatIgBi7lT2luUEN0dnpYSXc/view?usp=sharing
B
10
S
2
G
1
Posts: 51
Reputation: 848

Post » Sat Jan 02, 2016 10:10 pm

www.blackhornettechnologies.com/Constru ... e_BHT.capx

Keep track of the current item's UID, so you can exclude it, as needed.
ImageImageImage
B
71
S
21
G
203
Posts: 3,584
Reputation: 115,072

Post » Sat Jan 02, 2016 10:37 pm

blackhornet wrote:http://www.blackhornettechnologies.com/Construct2Stuff/helpmepickuponlyone_BHT.capx

Keep track of the current item's UID, so you can exclude it, as needed.

Can you explain the code? I'm glad to see it work, but I want to be able to learn it so maybe next time I can do something similar myself.

How does this code work if I had two different object types at the same time when I'm trying to pick up something?


Also, how can I add onto this an make a system to have a "carrying something" state for the player. I'm hoping to add custom animations and custom movements (mainly just slower, and weaker jump)
B
10
S
2
G
1
Posts: 51
Reputation: 848

Post » Sat Jan 02, 2016 11:38 pm

Image

By adding an instance variable to keep track of the currently picked item, you can always reference it in the future individually.

Ev17: On Z and overlapping Sprite2
-> Ev18: Tests to see if you are holding an item.
--> Ev19: Pickall Sprite2s again, in case the held item is not overlapping (which it will be in this case, but maybe a future item doesn't), and then pick just the held item
### Set that item as not picked up
-->Ev 20: Of the overlapping items, pick those that are NOT the held item AND then pick a random one
### Set the new item's pickup=True, and store that UID in the Player
-->Ev 21: ELSE (there were no other items to pick up, so) reset the stored UID so we know we aren't holding anything.

To deal with different types, you could use Families, or you have to deal with the combinations yourself.
ImageImageImage
B
71
S
21
G
203
Posts: 3,584
Reputation: 115,072

Post » Sun Jan 03, 2016 1:57 am

Thank you so much!
B
10
S
2
G
1
Posts: 51
Reputation: 848

Post » Sun Jan 03, 2016 2:27 am

I am not sure, but would it work better on z pressed drop all/disable wait 0.3 enable/pickup..

again I don't know much about coding. Just understand the basic concepts of how it would work.

Have Fun and Enjoy. ;) JC
B
29
S
13
G
10
Posts: 355
Reputation: 8,317


Return to How do I....?

Who is online

Users browsing this forum: Jazz813, KIDofGOD and 2 guests