Equipping and Unequipping

Get help using Construct 2

Post » Wed Feb 26, 2014 4:23 pm

So i need some help with Equipping and Unequipping my "spells".
Add www

dropbox.com/s/6t3galio2sb0b4a/Equippind_and_Disequipping_Test.capx

That is the capx but let me explain a bit first.
You equip spells by clicking on them and then choosing if you want to equip them on buttons: Q or W
That was easy but the following bothers me:

1. How can I make that only one spell can be equipped on Q or W at a time
2. When i decide to put "spell2" on Q but "spell1" is on its place how do i get "spell1" to unequip and "spell2" to equip

Thanks in advance, and if there is a simpler way i would like to know which way it is (obviously :lol: )
B
7
S
2
Posts: 102
Reputation: 975

Post » Wed Feb 26, 2014 4:43 pm

I haven't looked at your capx, so depending on how you made it. You can for each hotkey store the spell_UID, spell name or whatever makes them unique. And simply overwrite this value, from what I understand you want it to swap, but actually you don't need to swap, but just overwrite.

So if you have:

Hotkey_Q = Spell_1
Hotkey_W = Spell_2

And want to change Hotkey_Q, it doesn't really matter what happens to the spell that is already there, so you simply.

Set Hotkey_Q = Spell_2

And Spell_1 automatically gets "Unequipped".

So if you have already made it so you can equip a spell it should work fine if you overwrite them.

If you want to make sure that the player cant equip Spell_2 two times, you can check in Hotkey_W if Hotkey_Q not equal "Spell name" then equip spell.

And reversed for Hotkey_Q.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Wed Feb 26, 2014 6:16 pm

Actualy it is important because the way the spellcasting works is like this.
I have an invisible sprite with collision set off(hotkey_Q) and when there is another sprite which represents the spell on place where hotkey_Q is I do the following:

on key Q pressed > set hotkey_Q collision on
On hotkey_Q collision with spell_sprite > and then actions which cast the spell
B
7
S
2
Posts: 102
Reputation: 975

Post » Wed Feb 26, 2014 6:59 pm

I downloaded your capx. And have modified it. Just so you can see how to do it.

Personally I would consider changing the way you select spells, so you could simply left click to equip it in Q and right click to use W. But anyway, I have added comments to it, so you can see what each thing does.

However here are some further explanation.
1. I made a family that hold your spells, this is simply so you don't have to repeat the code as much. And to difference between the spells, I have just added a variable to the family called spell_nr. that goes from 1 to 3.

2. I have added 3 imagepoints to the spell bar, so each spell can be matched to a imagepoint location when they are swapped. Again this is simply to reduce the amount of code needed.

3. To the two Q and W buttons I have added a variable to hold the nr of the spell that is currently equipped. This is when it is replaced, I can return it to the spell bar, before placing the new one.

4. The Q W where you select which spell to equip, also have a variable called Selected_spell, which hold the Spell_nr that was chosen. This is so it knows which spell it should equip.

https://dl.dropboxusercontent.com/u/109921357/Equippind_and_Disequipping_Test.capx
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Wed Feb 26, 2014 7:03 pm

That is AMAZING man thank you sooo much. You have no idea how much you helped me. Thanks.
B
7
S
2
Posts: 102
Reputation: 975

Post » Wed Feb 26, 2014 7:06 pm

No problem :)
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848


Return to How do I....?

Who is online

Users browsing this forum: zenox98 and 8 guests