hello, i have a huge problem and dont know how to fix it. here is the code:

#(in class)
def shoot(self, current_time, bullet_group, enemy_group):
    if current_time - self.last_shot > self.shoot_count:
        bullet = Bullet(self.rect.centerx, self.rect.bottom, "death_star_laser1.png", 10)
        bullet_group.add(bullet)
        if current_time - self.last_shot > self.cooldown:
            self.last_shot = current_time
            return random.choice(enemy_group.sprites())     

#(just normal written in file)
if len(speed_enemy_group) > 0:
    choose_boss= random.choice(boss_enemy_group.sprites())

#(in while loop)
   if len(speed_enemy_group) > 0:
            choose_boss= choose_boss.shoot(time_now, enemy_bullet_group, boss_enemy_group)

i get error nontype ...

its because choose_boss(time_now,... --> choose_boss is yellow. but when i put the definition of choose boss in my while loop all is great but i wont do that because boss is shootng multiple bullets in one row and if i put "choose_boss= random.choice(speed_enemy_group.sprites())" in the while loop every time its another boss who shooting..

im happy if somebody can look at ths

Please post the exact error message and tell us what line is being flagged.

sory i forgot paste it.

  File "/home/kali/PycharmProjects/pythonProject5/main.py", line 556, in <module>
    choose_boss = choose_boss.shoot(time_now, enemy_bullet_group, boss_enemy_group)
                  ^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'shoot'

In lieu of any other information I would go with what you are being told. Ensure that random.choice is actually returning what you expect. It seems that what it is returning does not have a shoot attribute. Since it says it is a NoneType object it would appear you aren't getting back what you are expecting.

Breakpoints are your friend. I recommend getting and using the Visual Code app.

Hi there,

Based on the code snippet you provided, it looks like you're working on a game or simulation of some sort. It's unclear what the exact problem is that you're facing, but I can see a couple of issues with the code that you may want to address.

Firstly, in the shoot() function, there's a nested if statement where the second condition (current_time - self.last_shot > self.cooldown) seems to be redundant since the same condition is already being checked in the outer if statement. You may want to remove this to simplify the code and make it more efficient.

Secondly, in the while loop, you're assigning the result of the shoot() function to the choose_boss variable. However, the shoot() function doesn't seem to return anything if the second if statement (current_time - self.last_shot > self.cooldown) is not satisfied. This means that choose_boss will be assigned None in such cases, which may not be desirable. You may want to modify the shoot() function to always return a value (even if it's just None) so that choose_boss is always assigned a value.

I hope this helps, and good luck with your project!

commented: unfortunately not but i have done it now a little bit different but thanks for your answer :) +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.