简体   繁体   English

Python:无法分配给运算符

[英]Python: Can't assign to operator

Writing a battle sequence for a game, and this error is showing on the bottom line where the actual arithmetic should be occurring and being applied in the background. 编写游戏的战斗顺序,此错误显示在应该进行实际算术并在后台应用的底线。 I'm assuming it's an error related to method of the arithmetic? 我假设这是与算术方法有关的错误?

if choice == 'A':
        print(curChar[NAME] + "attacks!")
        attackHit = True
        if WEAPON_ACCURACY < 100:
            if roll() > WEAPON_ACCURACY:
                attackHit = False
                print(curChar[NAME], "'s attack missed!")

        else:
            attackHit == True
            print(curChar[NAME], "'s attack landed and dealt", curChar[STRENGTH] + curChar[WEAPON_DAMAGE] - curEnemy[HEALTH] + curEnemy[ARMOR], "damage!")
            **curChar[HEALTH] + curChar[ARMOR] - curEnemy[STRENGTH] - curEnemy[WEAPON_DAMAGE] = curChar[HEALTH]**

Be careful of the order in which you assign variables. 注意分配变量的顺序。 The target is on the left, the computation is on the right. 目标在左侧,计算在右侧。

curChar[HEALTH] = curChar[HEALTH] + curChar[ARMOR] - curEnemy[STRENGTH] - curEnemy[WEAPON_DAMAGE]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM