1

i getting the same problem again and again and don't understand why. i'm using Pycharm to code maybe it's something with the settings i'm not sure.

the problem: instance attribute ship_speed_factor defined outside init.

why does ship_speed_factor can't be outside the init if i want to call this variable while the variable change by the user while running.

def initialize_dynamic_settings(self):
        self.ship_speed_factor = 1.5
        self.bullet_speed_factor = 3
        self.alien_speed_factor = 1

        self.fleet_direction = 1

this is the full code

enter code here
class Settings():
"""A class to store all settings for Alien Invasion"""
def __init__(self):
    """"Initialize the game's static settings."""
    # Screen settings
    self.screen_width = 1100
    self.screen_height = 800
    self.bg_color = (230, 230, 230)

    # ship settings
    self.ship_limit = 3

    # bullet settings
    self.bullet_width = 6
    self.bullet_height = 15
    self.bullet_color = (60, 60, 60)
    self.bullets_allowed = 4

    # Alien settings
    self.fleet_drop_speed = 10

    # How quickly the game speed up
    self.speedup_scale = 1.1

    self.initialize_dynamic_settings()

def increase_speed(self):
    self.ship_speed_factor *= self.speedup_scale
    self.bullet_speed_factor *= self.speedup_scale
    self.alien_speed_factor *= self.speedup_scale

def initialize_dynamic_settings(self):
    self.ship_speed_factor = 1.5
    self.bullet_speed_factor = 3
    self.alien_speed_factor = 1

    self.fleet_direction = 1
Nisan Levy
  • 11
  • 3
  • Does this answer your question? [Instance attribute attribute\_name defined outside \_\_init\_\_](https://stackoverflow.com/questions/19284857/instance-attribute-attribute-name-defined-outside-init) – W Kenny Sep 25 '20 at 02:18

1 Answers1

0

This is probably a warning from PyCharm, not an error. The reason for this is that the linter checks if the instance attribute is defined in the __init__ method, since one might expect finding it there.

See Instance attribute attribute_name defined outside __init__

LorenzBung
  • 404
  • 1
  • 5
  • 15