我遇到了一些错误"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;
}
}
答案 0 :(得分:1)
不属性/变量名称的语法构造位于=
赋值运算符的 left 上:
// 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值的规范,稍微不幸的是它不会在这里产生更好的错误信息。