Why I get Error: assigning to rvalue?


#1

Hello all!
I have the code like above and get the error “assigning to rvalue”. Why?

if 1 + 1 + 1 = 3:
    self.moveXY(0, 16)  # Обход первой группы мин.
    self.moveXY(0, 12)
    self.moveXY(7, 12)
    self.moveXY(0, 12)
    self.moveXY(0, 16)
if 2 + 2 == 4:
	self.moveXY(15, 40)  # Передвижение к первому самоцвету.
if 2 + 2 == 4:
	self.moveXY(25, 15)  # Передвижение к второму самоцвету.
if 2 + 2 > 3:
    enemy = self.findNearestEnemy()
    self.attack(enemy)
if 2 == 4:
	self.moveXY(40, 55)
if False:
	self.moveXY(50, 10)
if True:
	self.moveXY(55, 25)

#2

Use == instead of = on the first line. = is a variable assigment, whereas == is an equality check. (This is one of the worst mistakes in programming operator choices ever made, but now almost every language has it, so we have to live with it.)


#3

Ouh! Thank you!
I can’t find it because interpreter point to other line.
The stupid level with stupid “if” You can remove it all and that would be winning code.

Can you told me. I catch the helm and the sword in this level (gems-or-death) but can’t find this items.
Have I really get them?


#4

Yup, you could just delete the if statements around the parts you wanted to actually fire. Most players will enjoy the if practice, though.

Nah, the sword and helmet are just there for decoration, and unfortunately they move when you walk next to them. Gotta fix that!


#5

Thanks for helping nick!


#6

Please Do not bring up dead topics as they will bring the topic up to the front page. Read the FAQ before posting, as this post has been left untouched for 2 Years.