Activation of bool not working

Hi,
I am working on enabling and disabling scripts.
i have a script called PlayerData(Short=PD) and in that script i have a few boolians called doubleJump, higherJumps and quickWalk(sorry for the bad naming) in an other script i have an method to apply these abilitys on a sertain buttun press. (also, i have two abilitys mainAbility and secondAbility)
the button press works by haveing a int and if a button is pressed it adds one to the “mainAbility” int. and here is what is going wrong, this is my method:

public void ApplyScriptsAbility()
    {
        switch (mainAbility)
        {
            case 0:
                PD.doubleJump = false;
                PD.higherJumps = false;
                PD.quickWalk = false;

               

                break;
            case 1:
                PD.doubleJump = true;
                PD.higherJumps = false;
                PD.quickWalk = false;

              

                break;
            case 2:
                PD.doubleJump = false;
                PD.higherJumps = true;
                PD.quickWalk = false;

               
                break;
            case 3:
                PD.doubleJump = false;
                PD.higherJumps = false;
                PD.quickWalk = true;

               

                break;
        }

        switch (secondAbility)
        {
            case 0:
                PD.doubleJump = false;
                PD.higherJumps = false;
                PD.quickWalk = false;

               

                break;
            case 1:
                PD.doubleJump = true;
                PD.higherJumps = false;
                PD.quickWalk = false;

               

                break;
            case 2:
                PD.doubleJump = false;
                PD.higherJumps = true;
                PD.quickWalk = false;

              
                break;
            case 3:
                PD.doubleJump = false;
                PD.higherJumps = false;
                PD.quickWalk = true;


                break;
        }
        Debug.Log(mainAbility);
      
    }

here i just check for mainAbility to be a sertain number and enable/disable bools. I have no idea why but for some reason secondAbility works just fine but mainAbility does not work, am i overseeing something or is it just gliched, and of course if you know how pls leave it down below.

Thanks in advance,
Chris

I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run?
  • what are the values of the variables involved? Are they initialized?

Knowing this information will help you reason about the behavior you are seeing.

If mainAbility is a float, how are you converting it to an int in order to use it in the switch statement?

Oh yea i thought i used a float but i am now checking the scipt and it was an int ill change the question and thanks for th heads up!

tnx for the reply, after i put in all the debugs in i found out that it should just run. the debug statement just runs when the case is true but still nothing is changed. I then thought maybe its someting to do with the second switch, but when i duplicated the secondAbility switch and changed secondAbility to mainAbility. nothing chaned

After re-reading your original post, I have to wonder if you know for sure that it’s not working.

Here’s why: you first use a switch on mainAbility and set the three bools (for example, let’s say you set them to this: PD.doubleJump = false, PD.higherJumps = false and PD.quickWalk = false), and then immediately reset them with secondAbility (so, let’s say they become this: PD.doubleJump = true, PD.higherJumps = false and PD.quickWalk = true).

As a result, you are only seeing what happens to secondAbility; because it immediately changes the bools from whatever mainAbility set them to. So, even though they changed with mainAbility, secondAbility changes them an instant later.

That could be why it doesn’t seem to work, even though it does.

If you needed to have different settings based upon the two different abilities, they should be set to different bools. What you’re doing here is only grabbing what comes from the secondAbility switch.