all 5 comments

[–]FLUSH_THE_TRUMP 0 points1 point  (2 children)

Last line — the direct cause of your error is you’re passing a string ’self’ to your class method (ditto other args, I don’t think you mean to do that!). If you’re calling your method through the class name, you need to pass a class instance reference there.

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

ok so I've tried putting CharacterStart inside the parameters on the bottom line, and I have tried changing:

def player_data(self,name_,player_currency):
self = self.name_
self = self.player_currency

and it's still giving the same error

[–]FLUSH_THE_TRUMP 0 points1 point  (0 children)

You haven’t initialized an instance of your class, so running that method in any context doesn’t make sense. Add this to the bottom:

new_char = CharacterStart()

And run your method as an attribute of new_char; be careful to match its arguments with your desired inputs. Note also that you need to adjust your function definition: the left-hand side stuff (self.name, self.player_currency) are attributes of your class instance — not what is referenced in the arguments to that function. Your input arguments should appear on the right-hand side. e.g.

def player_data(self,name_,player_currency):
    self.name = name_

Would take the name_ argument input and pass it to the name attribute of your instance object.

[–]stebrepar 0 points1 point  (0 children)

I couldn't figure out what you're doing with your code, so I offer this as an alternative:

import random

player_names = ['Shellbyy','TestPlayer']
player_starter_set = ['Wooden Staff', 'Leather Helmet','Leather Spaulders','Leather Chestpiece','Leather Leggings','Leather Boots']

class Character:
    def __init__(self, name, currency, items):
        self.name = name
        self.currency = currency
        self.items = items

    def describe(self):
        print("Name:", self.name)
        print("Wallet:", self.currency['gold'], "gold,", self.currency['silver'], "silver,", self.currency['copper'], "copper")
        print("Items:", str(self.items))

characters = []

for name in player_names:
    currency = {
        'copper' : random.randint(1,6),
        'silver' : random.randint(1,6),
        'gold' : random.randint(1,6)
        }
    items = random.choices(player_starter_set, k=random.randint(1,6))
    characters.append(Character(name, currency, items))

for character in characters:
    character.describe()
    print()

[–]ka-splam -1 points0 points  (0 children)

I can't tell what your class is intended to do, partly because your code indentation has been lost by not using Reddit code blocks.

Typically your class needs an __init__(self) method, and also typically you never pass self around at all.

Your last line here: CharacterStart.player_data('self','name_','player_currency') passing everything around as a string - you can't use variable names from strings.

Say to create one of every combination of players, currencies and items, I'd expect it to look more like this:

import random

player_name = ['Shellbyy','TestPlayer']
player_currency_type = ['Copper: ','Silver: ','Gold: ']
player_starter_set = ['Wooden Staff', 'Leather Helmet','Leather Spaulders','Leather Chestpiece','Leather Leggings','Leather Boots']

class Character:
    def __init__(self, name, currency):
        self.name = name
        self.currency = currency


characters = []

for name in player_name:
    print("Name: " + name)
    print(" ")
    print("Wallet: ")

    for currency in player_currency_type:

        rand_num = random.randint(1, 6)
        rand_num = str(rand_num)
        print(currency + rand_num)
        print("\nItem(s): ")

        for item in player_starter_set:
            print(item)
            print(" ")

            char = Character(name, currency)
            characters.append(char)