Deactivate things only if only 1 of 5 properies is true

Hi yall

I just finished an effect that gonna be played when the player is choosing weapon.
Everytime the player holds down SPACE KEY it should play but ONLY when there is one or more special abilities enabled

I have 6 boolen properties
Slot 0 = True ( this is basic weapon and always True)
Slot 1,2,3,4,5 = False ( these are special weapons that need to be unlocked)
====> in this case the fx should be off

I want the effect to be played when player has 1 of those special weapons. Can I achieve this with only few lines of code?

I imagine its like… if i not in range (1,5): fx off ?

Thanks

maybe you can add all values into an integer and if the result is not 1 the effekt doesnt start

I’m not sure, but if you mean the fx will play as long as one of the item in the list is True, then try this

for value in slots:
    if value is False:
        continue
    else:
        activate_fx()

I suggest:


def isAtLeastOneItemEnabled(items):
   for item in items:
      if item:
         return True
      return False

It woks like an OR controller.

You call it this way:


specialEffectEnabled = isAtLeastOneItemEnabled(slots[1:])

Thanks all for the suggestions

I dont know how to use it but due to the methods of Monster and guramarx, i came to this.


from bge import logic as log
import random as rand


def isAtLeastOneItemEnabled(items):
   for item in items:
      if item:
         return True
      return False


def main():


    c = log.getCurrentController()
    o = c.owner
    sc = log.getCurrentScene()


    fx= c.sensors["fx"]
    na = "lock_0"
    if specialEffectEnabled == isAtLeastOneItemEnabled(o[na]):
        if fx.positive: 
            if fx.repeat == o["trig"]:
                for i in range(0,10):     
                    rx = rand.randint(-60 , 60) 
                    ry = rand.randint(-30 , 30) 
                    rz = rand.randint(-30 , 30) 
                    px = o.worldPosition[0] + rx
                    py = o.worldPosition[1] + ry
                    pz = o.worldPosition[2] + rz
                   
                    b = sc.addObject("chip-pick_pa", o , 60)
                    b.worldPosition = (px,py,pz)  


main()



I describe the function again. These are 6 locks , the 0 one stands for the basic weapon, so we can ignore it. I want the FX to happen only if one or more of the lock_1/2/3/4/5 is True.


I think i can use this? Is it effective?


if fx.positive: 
        na = "lock_" + str(o["basic"])
        if o[na] == True:
            if fx.repeat == o["trig"]:
                for i in range(0,10):     
                    rx = rand.randint(-60 , 60) 
                    ry = rand.randint(-30 , 30) 
                    rz = rand.randint(-30 , 30) 
                    px = o.worldPosition[0] + rx
                    py = o.worldPosition[1] + ry
                    pz = o.worldPosition[2] + rz
                   
                    b = sc.addObject("chip-pick_pa", o , 60)
                    b.color = col[o["basic"]]
                    b.worldPosition = (px,py,pz)