Power-up Menu Blues

1 favourites
  • 14 posts
From the Asset Store
75 power-up sound effects; bonus and notification sounds, fanfares, harp glissandi, stabs, clock ticks, etc.
  • Use this if you are intending to use drag and drop functionality on a visual menu to drag and drop abilities [icons] into equipped slots (abilities/items/etc...) and use said menu to determine what abilities/items/etc... are currently equipped to your character

    So basically the idea is there are 16 abilities and 3 slots that you can equip them in, each ability is represented by an icon in the menu, you drag and drop the icons onto the slots to equip them. i have figured out how to get most of it working but i am stuck in the regard of getting the ability icons to return to their original positions once a new one is placed onto the slot.

    each ability has 4 instance variables atm (slot1active, slot2active, slot3active and notslotted)

    each ability has a text object associated to it and each slot has a text object associated with it

    the logic looks like this:

    if dropped and overlapping slot1/2/3 then set slot1, slot2, or slot3's text object to the said ability text object

    if slot(x) text object = ability(x) text object then set said ability (x)'s icon to slot position and set slot(x)active instance variable to true on that ability

    if slot(x)active instance variable is true on given ability then set slot(x)active instance ability to false for all other abilities (this goes through slot1/slot2 and slot3)

    if slot(1,2 and 3)active instance variables are false and notslotted is true then set ability icon to original position

    simultaneously if any ability is dropped anywhere but slot1,2 or 3 then return to original position

    i keep running into the problem that if slot(1,2,3)active instance variables are false then return to position, basically disables the ability to drag and drop them at all, however, if that logic isn't in there they don't return to their original positions. i added the notslotted instance variable in an attempt to disrupt this so it is not active one startup but then becomes active once it is slotted/unslotted, but i am not sure where/how to work in notslotted, or if that is truly the solution.

    does anyone have an idea as to how to approach this issue?

    my thinking is that there needs to be something that ensures that only 1 ability is slotted at a time on each slot, then something else that triggers the previous ability to return to original position once a new ability is equipped to a given slot. i just am not sure how the logic of this would look.

  • I think the slot should be using an instance variable, not an assigned text object. The variables for slot active are not required from what I'm reading. You don't need to say powerup A is active on slot1 by the way of an instance variable on the powerup, you would just have it equipped on slot1. If you can drag a powerup over a slot and replace one then I'm not sure if a check to see if something is in the slot is required either? You could resolve this by getting rid of the slot active instance variables. The slot active boolean could remain if the slot can be disabled so you can't drop powerups into it.

  • the slot and text objects are required for later when you're actually playing the game to determine which powerup is assigned to which button in-game, i just used the text to assign position for convenience but essentially the text represents "is equipped"

    the instance variables were to determine which power up is on which slot

    which obviously you understand

    however as i think it through the proposed solution would lead to this problem;

    slot 1 = 1 of 16 possible instance variables representing the 16 different abilities

    slot 2 = 1 of 16 possible instance variables representing the 16 different abilities

    and slot 3 = 1 of 16 possible instance variables representing the 16 diff abilities

    also makes sense to have a neutral state "notslotted" which states there are no powerups active on a given slot

    now you make it so if slot1 = ___ instance variable set that ability icon to position of slot1 and all others to original position

    and so on through the other slots

    however, if you did that then you wouldn't be able to equip more than 1 power up at a time because it would constantly be resetting the other positions every time you equipped 1 power up to ANY slot

    or is there something i missing with that?

    that is why the code became so complicated, it is just to determine if any one power up is currently slotted and prevent that power up icon from being moved if another is slotted, i mean honestly it seems the text objects and instance variable option is interchangeable however they both lead to this problem

    oh the reason i used text objects is i was going off what you suggested originally in my other post


    about making the slot instance variables = the powerup instance variables but thought the only way to do this was using text objects in place of the instance variables because as i understand you cannot make an instance variable = another instance variable, maybe you meant to make it a string instance variable but even then i ran into problems, regardless the aforementioned problem is what matters because everything is working other than the returning to original position once a new power up is slotted

  • You can make an inst var = another inst var but you already have too many. How does your game work? Do you need to see the dropping of powerups onto slots? Where are you dragging them from and do they swap? So the text is displaying the instance variable on the slot that seems fair. The redundant bit is the ability having instance variables called slot1 active etc. I don't know if it will work for your game but the best thing is to have the actual slot with the powerup images as frames and set these. It sounds like you are moving the powerup objects from place to place when there may be no need to do that but I don't know how your game works.

  • yeah that's how it works there are ability icons you drag and drop onto the different slots from a visible menu, the making them swap bit is literally all i am trying to solve here

    if there was only 1 slot then the slot1active, etc... instance variables would be redundant because you would only need the 1 slot to change out and it would be as simple as "is equipped" then do everything else

    however, because there are 3 slots if you set it so ;

    is ability 1 equipped, then reset positions on all other power ups

    then you couldn't assign more than 1 ability to more than 1 slot at a time, for every time you did it would reset all the others

    again you're right, this would work if it was only the 1 slot

    the actual problem is when assign ability 1 to slot 1 and then assign ability 2 to slot 1 they both stack up instead of returning ability 1 to its original position

  • You wouldnt need instance variables to track that but rather some logic around powerup dropped onto a powerup, set the powerup in the slot back to its original position and leave the new one in the slot.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • really my thought here is to make it either when overlapping a slot or in position then set notslotted to false and then there just needs to be some event that resets not slotted and in doing so that would return it to its original position

  • so for anyone interested i've progressed a little further by adding set notslotted to false when powerup is touching any one of the 3 slots, and then set it to true in the same line of code that sets all the other slot(x)active instance variables to false ((once a given powerup is equipped to said slot))

    now when you set any power to equipped it will save it as equipped and returns the other power ups to original positions when you exit the menu ((if you reopen the menu then the other power ups are at original positions and equipped are in the equipped slots))

    however, it appears that the return to original position works at first but then stops, i've noticed that it works correctly approximately 2 or 3 times before they begin stacking upon each other again

    i believe the reason for this is that the "return to original position" code has a trigger once condition so it does not interfere with the drag and drop functionality ((without the trigger once you cannot move them at all as the conditions are set upon layout start and it keeps them at their positions))

    my immediate solution would be "every x seconds, if notslotted, then return to original position" however, the timescale is set to 0 when this menu is open as the game is paused, meaning ((i believe)) that the every x seconds function won't work

    if anyone has an idea on what to use instead of "every x seconds" that doesn't rely on the timescale being set to 1, please share your thoughts

  • also i think you are right about changing it to animation frames rather than objects themselves, that might be easier to work with, hopefully i can find an alternative fix though because that would require quite a bit of reworking

  • I think I figured it out

    Every time a power becomes equipped to slot(x) add 1 to slot(x) counter [number variable]

    Every time slot(x) counter is above 1 check every power up; for every power up that is not equipped [notslotted = true] then reset position and reset counter to 0

    I think this will create a constant check that resets position without relying on the timescale

    I will update once I have implemented and let know if it worked or not

  • Still having issues, it kind of works, however, when you place it it enters an infinite loop of glitching between the two spots, most likely because it checks if over one, changes positions based on notslotted variable, then resets the counter so it kind of goes from one to the other over and over because it is constantly switching between slotted and notslotted, need to find a way to break it up

  • These long discussions is what PMs used to be for I suppose. At least you understand the logic enough to see the bugs and kind of know where to fix them so that should be enough to get you going. If you get blocked you will simply have to share the project at that point )

  • that seems counter productive, (shutting down this post i mean) i feel like this topic could help others trying to implement something similar once it is fixed, if nothing else everything discussed has led to two pretty solid solutions;

    either use drag and drop method if timescale is set to 1 (and thus you can have an "every x seconds" change to _____ position; based on consequent conditions)


    use your suggestion of animation frame changes with touch controls to accomplish the same thing

    either way thank you for your help through this, and Moderators if you do intend to shut this down please give me some time because i am using this thread as a base to modify my project

    quick edit:

    Got a little further by using the slot1text = power.uptext (inverted) as the condition that returns to original position rather than using notslotted.

    the problem really lies with the conditions that start triggered to the same conditions that return to original position (Notslotted = true, Slot1active = False, Slot2Active = False, Slot3Active = False) this keeps not only making it so they return to position when you try to slot/equip them, but also (for some reason) they don't appear to be cooperating with the SlotCounter position reset. however, i believe the text condition got me further because it only triggers to true ONCE you equip it, allowing it to activate only after another has been equipped (again, that was accomplished by using the add 1 to SlotCounter, if SlotCounter is over 1 check all powerups, for every power up not equipped (now using text logic) return to original position)

  • Finally figured out how to break it up, added is notslotted false condition to the reset position toggle, and had to add a reset trigger to notslotted (setting back to true) once it resets position, this correlates to the SlotCounter function [SlotCounter is a number instance variable on each of the slots].

    the logic looks like this;

    is power up overlapping slot?

    is SlotCounter > 0

    Slot1/2/3 text = powerup.text

    is not slotted false


    set powerup position back to original x,y

    set SlotCounter to 0 on Slot1/2/3

    set NotSlotted to true on powerup


    seems to work initially with all powerups on each slot individually, however, if you attempt to equip 2 or more at one time they begin stacking again, will update when i understand why

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