1

我遇到了一些错误"1050: Cannot assign to a non-reference value.",我对编码还是很陌生,所以无法修复这个错误令人沮丧,任何帮助将不胜感激。

var PracticeDummyHealth:int=50
var PlayerAttack:int=20;

public function PlayerAttackFunction(){
    if(PracticeDummyHealth>0){
        PracticeDummyHealth-PlayerAttack=PracticeDummyHealth;
    }
}
4

1 回答 1

1

不是属性/变量名称的语法结构位于赋值运算符的左侧:=

// expression                   = expression
PracticeDummyHealth-PlayerAttack=PracticeDummyHealth;
// which makes as much sense to ActionScript as .. it's not an equation solver :)
// 100 - 50 = 100

与此有效代码进行比较:

// variable         = new_value
PracticeDummyHealth = PracticeDummyHealth - PlayerAttack;
// or
PracticeDummyHealth -= PlayerAttack;

请注意,在这两种情况下,“引用”(阅读:属性/变量名称)都出现在(或复合)的左侧这个术语来自处理 l 值的规范,不幸的是它在这里没有产生更好的错误消息。=-=

于 2012-11-04T07:00:32.793 回答