Reputation: 39
I'm having some trouble with the error "1050: Cannot assign to a non-reference value."
I'm still fairly new to coding, and so being unable to fix this error is frustrating, any help will be greatly appreciated.
var PracticeDummyHealth:int=50
var PlayerAttack:int=20;
public function PlayerAttackFunction(){
if(PracticeDummyHealth>0){
PracticeDummyHealth-PlayerAttack=PracticeDummyHealth;
}
}
Upvotes: 1
Views: 1514
Reputation:
An grammar construct which is not a Property/Variable name is on the left of the =
assignment operator:
// expression = expression
PracticeDummyHealth-PlayerAttack=PracticeDummyHealth;
// which makes as much sense to ActionScript as .. it's not an equation solver :)
// 100 - 50 = 100
Compare with this valid code:
// variable = new_value
PracticeDummyHealth = PracticeDummyHealth - PlayerAttack;
// or
PracticeDummyHealth -= PlayerAttack;
Note that a "reference" (read: Property/Variable name) appears on the left of the =
(or compound -=
) in both of these cases. This terminology comes from the specification which deals with l-values and it is slightly unfortunate it doesn't yield a nicer error message here.
Upvotes: 1