Equipping and Unequipping

0 favourites
  • 6 posts
  • So i need some help with Equipping and Unequipping my "spells".

    Add www


    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 )

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • 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.


  • That is AMAZING man thank you sooo much. You have no idea how much you helped me. Thanks.

  • No problem

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)