"Swapping Powers" Works With Breakpoints; Does Not Work Without Breakpoints

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
75 power-up sound effects; bonus and notification sounds, fanfares, harp glissandi, stabs, clock ticks, etc.
  • (My apologies if the subject line is confusing. I couldn't figure out how to summarize the issue in a single line.)

    c3p file: https://drive.google.com/file/d/11FYrqAQ4IxS15PrvgXGqd9CD4LA9hCsp/view?usp=sharing

    THE GOAL

    My game focuses on being able to select three superpowers from an assortment of classic comic book-style powers. During actual gameplay, the Player can press the I, O, and P keys to swap between the three powers. Only one power at a time can be active. So far, the power swap system I have in place is working...mostly. But I'll get to the problem shortly.

    THE SETUP

    On the HUD, I have three instances of the same object - ActivePower_HUD - which has three instance variables: SlotNumber (num), Is_PowerActive_HUD (bool), and ActivePower_Name (str).

    SlotNumber - Indicates the object instance's index position on the screen and so it can be easily referenced within the event sheet.

    Is_PowerActive_HUD - To set the frame number of the active animation of that particular object instance. The 0 or 1 value of the boolean makes it easy to set the frame.

    ActivePower_Name - This value comes from the object instance's animation name. (Prehaps redundant, as I need only call the object's animation.) This way, ideally, I can minimize extra event blocks by not having multiple HUD objects per power.

    When the I, O, or P keys are pressed, it calls the function SetActivePower with three parameters:

    PassTo_ActivePowerSlot

    Set_Slot_Inactive_1

    Set_Slot_Inactive_2

    The first variable corresponds to the ActivePower_HUD object instance that is intended to be the new active power. The other two, naturally, are the inactive powers. These variables will only ever have the values 1, 2, or 3. (So, if the O key is pressed, then the value of 2 will be passed to PassTo_ActivePowerSlot because that's going to be the new active power. Whatever power was chosen second at the start of the game will be in the second power slot on the HUD of the game screen.)

    When the function is actually processing, it picks by comparison each instance of the ActivePower_HUD object. It then assigns the Hero object (the one the Player controls) the corresponding power associated with the ActivePower_HUD instance in question. (It also assigns the inactive powers to other variables associated with the Hero, but these do not come into play yet and are just me trying to think ahead...)

    Next, I originally tried to make this system work using function mapping (and I do believe it would have worked) but I couldn't figure out how mapping works so my theory and a much simpler implementation will have to be worried about later. When the active superpower value got passed to the Hero object from the ActivePower_HUD instance object, a series of event blocks checks to see what the value of Hero.ActiveSuperPower (str) is. It also confirms that the relevant boolean instance variable is false.

    Example: Active superpower is Flight.

    IF...

    -> Hero.ActiveSuperPower = "Flight"

    -> Hero.Athlete = false

    Then...

    -> (Do these actions, including setting the Hero.[boolean] to true.)

    This is meant to simply activate the powers and set the parameters of that power.

    After that, another set of event blocks checks to see if the Hero.[boolean], as related to the active superpower, is true. If it is true, it again confirms that the related string variable, Hero.ActiveSuperPower, is still the correct corresponding value. If all checks out, then the controls for that superpower work as indicated.

    However, when a superpower gets swapped out, then Hero.ActiveSuperPower gets updated but Hero.[boolean] is still true (momentarily). When the boolean is true but the superpower value is no longer that superpower, then the superpower is "deactivated" and the related boolean is set to false. Ultimately, this was the best way I could think of to turn the powers on and off without having superpower overlaps.

    Thank you for bearing with me...now to get to the problem.

    THE PROBLEM

    So far, I have only three working powers: Athlete, Flight, and Invisibility. Flight works fine, and swapping between powers is also working. And technically, Athlete and Invisibility also work (though the Hero doesn't actually go invisible...yet). The issue is that when I swap between Athlete and Invisibility, the associated behavior does not work. And both use the Platform behavior but with different property values for the behavior.

    So, I can switch between Flight and Athlete and Flight and Invisibility just fine. No problem. The issue is that when I swap between Athlete and Invisibility, the Platform behavior will get disabled when swapping from one power but for some reason does not get re-enabled when swapping to the other power.

    The odd thing is that I test this by adding breakpoints at event lines 22, 29, and 37 (Hero.ActiveSuperPower = "[power]") and it worked!! When a breakpoint was reached, I swapped between the two powers that both use the Platform behavior. And each time, the Platform behavior was enabled as it should be!

    Again, I apologize for the length of this help request, but I wanted to make sure everything was as clear as could be. I could use some help figuring out why this works with breakpoints but not without them.

  • I know the cause will be to do with the many conditions but I don't really want to spend time trying to work out where exactly, instead I will say I think the bools are unnecessary unless there is something about the game design I'm not aware of. I would rework this to just use 'active power' and set up the player and behaviours for that power based on this, no need to add complexity with the bools on player as it is creating bugs. It will be very simple if you scrap the bools and have active power set without checking if you don't have other powers.

    All could be one in one function, for example :

    on I pressed - run function 'assign power' with slot 1 power name

    on O pressed - run function 'assign power' with slot 2 power name

    on P pressed - run function 'assign power' with slot 3 power name

    function 'assign power'

    - if 'power = Flight' - disable platform, enable 8 direction

    - if 'power = Invisibility' - disable 8 direction, enable platform

    - if 'power = Athlete' - disable 8 direction, enable platform, set speed

    etc

    For UI display things you can check what the current power is, if the name of the slot is not this power then you dim them etc You can assign current power to a global variable at the point you press I, O, P, and use it in this way.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Everything will work if you reset all the booleans and disabled all the behaviors in the function SetActivePower(). You need to set the actions before picking the HUDs though.

    Anyway, this is not the proper way of doing something that simple. You somehow messed up the order of the events... that's why when your behavior got enabled, another action disabled it instantly. (E.g when switching from Athlete to Invisible line 18 triggers which enables the Platform behavior but line 26 will also run which disables the behavior right away since the bool "Athlete" was not yet reset to false)

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