I'm new, please bear with me. Below is my code:
class Player():
name = "UnknownName"
stren = 10
dex = 10
con = 10
intel = 10
wis = 10
cha = 10
def randAssign(self):
global stren, dex, con, intel, wis, cha
stat_List = [stren, dex, con, intel, wis, cha]
for stat in stat_List:
r_1 = random.randint(1,6)
r_2 = random.randint(1,6)
r_3 = random.randint(1,6)
r_4 = random.randint(1,6)
stat_Val = r_1 + r_2 + r_3 + r_4 - min(r_1, r_2, r_3, r_4)
stat = stat_Val
randAssign is a method in Player() I'm trying to set a player's stats randomly, and need to rewrite the class variables at the time randAssign() is activated. For one reason or another, the use of global passes the following error:
NameError: name 'stren' is not defined.
Using Nonlocal yields this error:
SyntaxError: no binding for nonlocal 'stren' found
Without either global or nonlocal, it just doesn't rewrite Player()'s
variables.
I've done a dozen iterations of this, from the outright wrong to the "I thought this would work but it doesn't", and need help.