lundi 10 août 2015

python random.choice in a class

I am trying to work on some code for something I am starting to make but I tested a short part of something important in my project and it doesn't seem to work as I want. Here's the small segment of my code I tested:

    class Fighter_Fish(object):   #class to manage all fishes and their stats
fish_sum = 0

def __init__(self,fish_name, fish_type, dice_list ,skill, trigger):
    self.fish_name = fish_name
    self.fish_type = fish_type
    self.dice_list = dice_list
    self.skill = skill
    self.trigger = trigger

def dice_spin(self): #commences dice spin for current turn
    fish_sum = random.choice(self.dice_list)
    if fish_sum == "W":
       fish_sum = 0
       self.skill_commence()


clown_fish_list = ["1","2","2","2","3","3"]
clown_fish = Fighter_Fish("Clown_Fish","Def",clown_fish_list,"None","None")

clown_fish.dice_spin()
print (clown_fish.fish_sum)

The print should print one of the strings in from my tested list, but it returns 0

Am I using the class functions wrong?




Aucun commentaire:

Enregistrer un commentaire