How to Stop Using so Meny Booleans?

Hi:

I have a script that controls my turret, but I am wondering how to script a talent system for my turret in the “FireProjectile” method. I was thinking something with booleans to check if they are on, and if so. Do what is needed. The problem I am thinking of is that scripting it this way will have a lot of booleans checks when firing (will it matter if I add lets say 20 booleans to “FireProjectile” method?) and might slow down my game to much. Is there maybe another way to go about scripting this?

Thank You: James

P.S.
I am still learning scripting in C# so be gentle

What will slow you down is complex, convoluted and nested condition checking. Having many booleans is fine. Just do not attempt to poll too many at a time.

if(bool1 && bool2 && bool3 && bool4 && bool5 && bool6)
  etc  //SLOW !!!! DO NOT ATTEMPT

if(bool1)
{
    if(bool2)
    {
        if(bool3)
        {
            if(bool4)
            {//EVEN SLOWER!!}
        }
    }
}

If you do have many many flags to consider, you could attempt a (unsigned) int based bit-masking system.

An integer has 32 bits. You can treat each of these bits like a flag and so you can effectively control 32 booleans with 1 single integer value.

I must say how the hell you have 20 booleans just for a firing script?

Well, i should suggest you to think more clearly, more basic. Don’t think very complicated, that will force you to do unnecessary if-else checks, use wrong loops, declare too many unnecessary variables and even try to write you own classes/methods for things that can easily be done with built-in ones, etc…

Always try to figure out what are you going to do, how are you going to do, and what you want to be ended up with. If the code doesn’t do the things you want, don’t even try to modify it; just erase and write again. Believe me, modifying will be much more complicated and will take more time than writing from scratch.

And the most important point: you may try to have a break when you feel that you can’t handle the whole code block anymore, go and breathe some fresh oxygene, it will cause some dizziness though, but also makes your brain work faster.

Best wishes and good luck!