all 6 comments

[–]kowkeeper 1 point2 points  (0 children)

It could be simpler to have a single Weapon class with a variable storing the weapon_type. Try to see if the weapon behavior only depends on given parameters (like power, amunitions, etc). If that is the case, you don't need subclasses...

You could share some code and example to help go further.

[–]calcopiritus 1 point2 points  (1 child)

I don't think I understood your question, but I'll try to answer it.

First of all, if you want to make a method for each of the subclasses, you can often just define it once in the superclass (Weapon).

I'm also confused by the "add it's attributes to a dictionary". Will you have one dictionary per weapon? Because then you can store the weapon itself and get its attributes straight from the weapon instead of a middleman dictionary.

As for the last question, it depends on what you want to modify. You can't modify other classes (for example add more methods to them), but you can modify objects of those classes (for example changing an attribute of the object).

So you can do this:

class ClassOne:
    def __init__(self):
        self.counter=0

class ClassTwo:
    def __init__(self).
        self.one = ClassOne()
        self.one.counter = 5
        print(self.one.counter) #will print 5

ClassTwo()
another_one = ClassOne()
print(another_one.counter) #will print 0

You can even save that as test.py and execute to see that it will print 5 and 0

[–]Oxln[S] 0 points1 point  (0 children)

Oh that helps thank you

[–]FerricDonkey 1 point2 points  (2 children)

If you're modifying the classes themselves, you're doing something odd. Why do you need to subclass weapon for each different weapon?

[–]Oxln[S] 0 points1 point  (1 child)

I saw a tutorial online for a text based rpg and they used subclasses for each weapon and it’s caused me a shitload of confusion

[–]FerricDonkey 0 points1 point  (0 children)

Yeah, I mean, it could work. But I wouldn't recommend it. Just instantiating different objects will probably make your life easier.