Inventory weapons (Drag and drop)

Get help using Construct 2

Post » Tue Jan 21, 2014 6:46 am

What I have:
I have 2 boxes at the bottom of the screen and an inventory with weapons.

What I want to do:
- When I drag a gun from my inventory to slot 1, I want it linked to key 1
- When I drag a gun from my inventory to slot 2, I want it linked to key 2
- When I press key 1 or 2, it should pull out the correct weapon I dragged there

Question:
What is the best way to do this? Should I use arrays? If so, how?
B
60
S
19
G
3
Posts: 451
Reputation: 6,364

Post » Tue Jan 21, 2014 7:32 am

i would do it with families and instance variables.
put all weapons into one family called all_weapons i.e and give them a family instance variable called "ID" or something like this. Make a family for the slots too. -> all_slots. with instance variables "number" 1 and 2.
give the player instance variables like "weaponsEquipted1" & 2.

give the family all_weapons drag&drop behaviour.
then do somethin like this:

"all_weapons" On overlapping "all_slots"
-> Set value "weaponsEquipted"&"all_slots.number" to all_weapons.ID

and then if 1 or 2 are pressed:

on 1 key pressed
---compare instance variable all_weapons.ID = weaponsEquipted1 (this is a subevent)
-> set all_weapons position to player at image point whatever ...
-> set drag'n'drop of all_weapons to disabled
-> set position of all_weapons to itemslot1.X,itemslot1.Y

so the player won't be able to remove them by accident if they are selected.

i can send you a capx this evening if you don't get it. or send me your's and i'll show you what i mean.philx2014-01-21 07:37:44
B
23
S
6
G
5
Posts: 132
Reputation: 4,487

Post » Tue Jan 21, 2014 7:35 am

of course you can use an array instead of all these instance variables.
depending on what you plan to do with your weapons further in the game this would even be better. for example if you have different stats for reloading time, recoil, firerate and so on ..

i can show you how to do it with arrays aswell.
B
23
S
6
G
5
Posts: 132
Reputation: 4,487

Post » Wed Jan 22, 2014 12:38 am

Thanks. Would you happen to have a good capx example? If not, explanation of the array option would be nice! Thank you!
B
60
S
19
G
3
Posts: 451
Reputation: 6,364


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests