如何在方法中定义全局变量(Python)?

时间:2019-05-14 00:38:10

标签: python python-3.x

该功能未检测到全局变量“ health_player”。

def Stats():
    global health_player
    global armor_rating_player
    global damage_player
    global mana_player
    global stamina_player
    global accuracy_player
    global speed_player
    global strength_player
    global magic_stat_player
Stats()

if Class == "Mage" or Class == "mage" or Class == "m" or Class == "M":
    health_player = 50
    armor_rating_player = (items[Mage_equipped[0]]*0.15)+(items[Mage_equipped[1]]*0.20)\
                          +(items[Mage_equipped[2]]*0.10)+(items[Mage_equipped[3]]*0.10)
    magic_stat_player = 50
    damage_player = (items[Mage_equipped[4]]+(items[Mage_equipped[4]]*(magic_stat_player/100)))
    mana_player = (magic_stat_player*0.6)
    dexterity_player = 85
    speed_player = (dexterity_player*0.8)
    equipped = Mage_equipped
    inventory = ['Health Potion' * 3, 'Mana Potion' * 4 ]
    Class = 'Mage'
elif Class == "Warrior" or Class == "warrior" or Class == "w" or Class == "W":
    health_player = 60
    armor_rating_player = (items[Warrior_equipped[0]]*0.15)+(items[Warrior_equipped[1]]*0.20)\
                          +(items[Warrior_equipped[2]]*0.10)+(items[Warrior_equipped[3]]*0.10)
    strength_player = 45
    damage_player = (items[Warrior_equipped[4]]+(items[Warrior_equipped[4]]*(strength_player/100)))
    stamina_player = (strength_player*1.2)
    dexterity_player = 80
    speed_player = (dexterity_player*0.8)
    equipped = Warrior_equipped
    inventory = ['Health Potion' * 3, 'Stamina Potion' * 4]
    Class = 'Warrior'
elif Class == "Ranger" or Class == "ranger" or Class == "r" or Class == "R":
    health_player = 40
    armor_rating_player = (items[Ranger_equipped[0]]*0.15)+(items[Ranger_equipped[1]]*0.20)\
                          +(items[Ranger_equipped[2]]*0.10)+(items[Ranger_equipped[3]]*0.10)
    strength_player = 40
    damage_player = (items[Ranger_equipped[4]]+(items[Ranger_equipped[4]]*(strength_player/100)))
    stamina_player = (strength_player*1.2)
    dexterity_player = 90
    speed_player = (dexterity_player*0.8)
    equipped = Ranger_equipped
    inventory = ['Health Potion' * 4, 'Stamina Potion' * 4]
    Class = 'Ranger'

我希望可以检测到该变量。

也就是说the link是完整的文件,由于字符限制,我无法在此处复制所有代码。

0 个答案:

没有答案